[英]Problems on select module on Python 2.5
我在 Python 2.5 中有一个应用程序,它监听 beanstalk 队列。 它在我迄今为止测试过的所有机器上都能正常工作,除了我新买的 MacBook Pro。
在该计算机上,当我尝试运行它时,出现此错误:
Traceback (most recent call last):
File "jobs.py", line 181, in <module>
Jobs().start()
File "jobs.py", line 154, in start
self.jobQueue = Queue()
File "src/utils/queue.py", line 16, in __init__
self.connection = serverconn.ServerConn(self.server, self.port)
File "src/beanstalk/serverconn.py", line 25, in __init__
self.poller = select.poll()
AttributeError: 'module' object has no attribute 'poll'
serverconn.py 有以下导入:
import socket, select
当我尝试从命令行运行它时,它也失败了:
Python 2.5.1 (r251:54863, Jul 23 2008, 11:00:16)
[GCC 4.0.1 (Apple Inc. build 5465)] 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'
您对可能发生的事情有任何想法吗?
PS:尽管我很确定这不是源问题,但如果您需要有关失败的源的一些背景信息,可以在 [ http://pastie.org/399342](this paste)上找到它。
更新:自从我得到第一个答案以来,我推测 Mac OS 是否支持 select.poll() ,但我也有一台 iMac 并且具有完全相同的操作系统版本并且它工作正常:
2009-02-25 00:27:10,067 - Queue - DEBUG - Connecting to BeansTalk daemon @ localhost:11300
根据这张 macports 票,Apple 的 poll() 实现直接被打破了。 Apple 通过在 Python 中禁用 poll() 来解决这个问题,并且 macports 现在也在其 Python 中禁用 poll。 我认为这意味着您需要查看 Python 的 select.kevent() 而不是 mac 上的 poll 。
(并非所有操作系统都支持。 )返回一个轮询 object,支持注册和注销文件描述符,然后轮询它们的 I/O 事件; 有关轮询对象支持的方法,请参阅下面的轮询对象部分。
我的猜测是 macOS 不支持它。
在您的 MBP 上使用python
的MacPorts版本。
Mac OS X 支持这一点。 苹果股票 Leopard python 2.5.1
没有。
如果您还没有,您将需要下载并安装 MacPorts。 仅供参考,我发现Porticus是 MacPorts 周围的优秀 GUI。
这是库存 Leopard python 与最新 MacPorts python2.5 的比较...
来自 Apple(python 2.5.1)的 Leopard python - select.poll()
损坏
$ /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()
有效!
$ /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>
>>>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.