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 Pastie)。
更新:因为我得到的第一个答案推测 select.poll() 是否受支持Mac 操作系统,但我也有一台 iMac,并且具有完全相同的操作系统版本,并且运行良好:
2009-02-25 00:27:10,067 - Queue - DEBUG - Connecting to BeansTalk daemon @ localhost:11300
I have an application in Python 2.5 that listens to a beanstalk queue. It works fine on all machines I tested so far, except from my newly acquired MacBook Pro.
On that computer, when I try to run it I get this error:
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'
The serverconn.py has the following imports:
import socket, select
And when I try to run it from command line, it fails as well:
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'
Do you have any idea on what can be happening?
PS: Even though I am pretty confident it's not a source problem, if you need some background on the source that's failing, it's available at [http://pastie.org/399342](this pastie).
Updated: since the first answer I got speculates whether select.poll() is or not supported on Mac OS, but I have an iMac too and with the exact same OS version and it works fine:
2009-02-25 00:27:10,067 - Queue - DEBUG - Connecting to BeansTalk daemon @ localhost:11300
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
根据 这张 macports 票,苹果对 poll() 的实现直接被破坏了。 Apple 通过在 Python 中禁用 poll() 来解决此问题,并且 macports 现在也在其 Python 中禁用 poll。 我认为这意味着您需要研究 Python 的 select.kevent() 而不是 mac 上的 poll 。
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.
我想你的答案就在这里
http://atomized .org/2008/12/python-on-os-x-leopard-lacks-selectpoll/
I think your answer is here
http://atomized.org/2008/12/python-on-os-x-leopard-lacks-selectpoll/
在 MBP 上使用 MacPorts 版本的
python
。Mac OS X 支持此功能。 Apple Stock Leopard
python 2.5.1
没有。如果您还没有下载并安装 MacPorts,您需要下载并安装。 仅供参考,我发现 Porticus 是围绕 MacPorts 的优秀 GUI。
这是库存 Leopard python 与最新 MacPorts python2.5 的比较...
Apple 的 Leopard python (python 2.5.1) -
select.poll()
损坏Macports (python 2.5.4) -
select.poll()
有效!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()
brokenMacports (python 2.5.4) -
select.poll()
works!select.poll()
(并非所有操作系统都支持。)返回一个轮询对象,该对象支持注册和取消注册文件描述符,然后轮询它们以获取 I/O 事件; 有关轮询对象支持的方法,请参阅下面的“轮询对象”部分。
我的猜测是 macOS 不支持它。
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.