Problems on select module on Python 2.5

坚强是说给别人听的谎言 提交于 2019-12-01 09:10:27

use the MacPorts version of python on your MBP.

Mac OS X supports this. Apple stock Leopard python 2.5.1 does not.

you will want to download and install MacPorts if you have not already. FYI, I find Porticus to be an excellent GUI around MacPorts.

here is a comparison of stock Leopard python vs. latest MacPorts python2.5...


Leopard python from Apple (python 2.5.1) - select.poll() broken

$ /usr/bin/python
Python 2.5.1 (r251:54863, Jan 13 2009, 10:26:13) 
[GCC 4.0.1 (Apple Inc. build 5465)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import socket, select
>>> select.poll()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'poll'
>>> 

Macports (python 2.5.4) - select.poll() works!

$ /opt/local/bin/python2.5
Python 2.5.4 (r254:67916, Feb  3 2009, 21:40:31) 
[GCC 4.0.1 (Apple Inc. build 5488)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import socket, select
>>> select.poll()
<select.poll object at 0x11128>
>>> 

According to this macports ticket Apple's implementation of poll() is straight up broken. Apple worked around this by disabling poll() in Python and macports now disables poll in their Pythons as well. I think this means you need to look into Python's select.kevent() instead of poll on mac.

select.poll()

(Not supported by all operating systems.) Returns a polling object, which supports registering and unregistering file descriptors, and then polling them for I/O events; see section Polling Objects below for the methods supported by polling objects.

My guess is that it's not supported on the macOS.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!