Python 2.5上选择模块的问题

时间:2009-02-25 03:12:49

标签: python macos beanstalkd

我在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获得。

更新:自第一个答案以来我推测是否支持Mac OS上的select.poll(),但我也有一个iMac,并且具有完全相同的操作系统版本,并且工作正常:

2009-02-25 00:27:10,067 - Queue - DEBUG - Connecting to BeansTalk daemon @ localhost:11300

4 个答案:

答案 0 :(得分:6)

根据this macports ticket,Apple的民意调查()实施是直截了当的。 Apple通过在Python中禁用poll()来解决这个问题,而macports现在也禁用了Pythons中的poll。我认为这意味着你需要研究Python的select.kevent()而不是mac上的poll。

答案 1 :(得分:2)

答案 2 :(得分:0)

select.poll()

并非所有操作系统都支持。)返回一个轮询对象,它支持注册和取消注册文件描述符,然后轮询它们以查找I / O事件;有关轮询对象支持的方法,请参阅下面的轮询对象部分。

我的猜测是macOS不支持。

答案 3 :(得分:0)

在您的MBP上使用python版本的python 2.5.1

Mac OS X支持此功能。 Apple股票Leopard select.poll()没有。

如果您还没有,则需要下载并安装MacPorts。仅供参考,我发现MacPorts是围绕MacPorts的出色GUI。

这里是Leopard python与最新MacPorts python2.5的比较...


来自Apple的Leopard python(python 2.5.1) - $ /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' >>> 已破坏

select.poll()

Macports(python 2.5.4) - $ /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> >>> 有效!

{{1}}