Unable to use Python select.poll on 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' 
+6
source share
3 answers

Instead of using polling, use select.kqueue () on OSX. It is similar to "epoll" on Linux, because you can more efficiently log file descriptor / file system event types that can be used in asynchronous code. Much more effective than polling.

Otherwise, the equivalent simply triggers the select.select () lock inside while True: loop with some kind of timeout?

+6
source

If you want to use polling so as not to rewrite a bunch of code for kqueue, it is built into python compiled from macports (macports.org). You just have to specify this python instance explicitly (/opt/local/bin/python2.7 in my case), because OSX python (/ usr / bin / python) will be earlier in the search path by default.

+1
source

Interestingly, for future references, this is only due to a limited subset of python versions

 user@hostname :~/ws/engine$ python Python 2.7.9 (v2.7.9:648dcafa7e5f, Dec 10 2014, 10:10:46) [GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> import select >>> select.poll() <select.poll object at 0x102415cc0> >>> exit() user@hostname :~/ws/engine$ python --version Python 2.7.9 user@hostname :~/ws/engine$ workon py_2_7_10 (py_2_7_10) user@hostname :~/ws/engine$ python Python 2.7.10 (default, Oct 23 2015, 19:19:21) [GCC 4.2.1 Compatible Apple LLVM 7.0.0 (clang-700.0.59.5)] 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' >>> ~/ws/engine$ uname -a Darwin hostname 15.4.0 Darwin Kernel Version 15.4.0: Fri Feb 26 22:08:05 PST 2016; root:xnu-3248.40.184~3/RELEASE_X86_64 x86_64 
+1
source

Source: https://habr.com/ru/post/957237/


All Articles