Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot use Python select.poll in Mac OS?

$ python
Python 2.7.5 (default, Aug 25 2013, 00:04:04) 
[GCC 4.2.1 Compatible Apple LLVM 5.0 (clang-500.0.68)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import select
>>> select.poll
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'poll'
like image 442
Zhang Jiuzhou Avatar asked Nov 02 '13 09:11

Zhang Jiuzhou


1 Answers

Instead of using poll, use select.kqueue() on OSX. It's similar to 'epoll' on Linux in that you can more efficiently register for types of file-descriptor / file system events which can be used in asynchronous code. Much more efficient than polling.

Otherwise, the equivalent is just running a blocking select.select() inside a while True: loop with some sort of timeout?

like image 181
synthesizerpatel Avatar answered Sep 30 '22 22:09

synthesizerpatel