编程语言
首页 > 编程语言> > Python 2.5上选择模块的问题

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]获得.

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

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

解决方法:

在你的MBP上使用MacPorts版本的python.

Mac OS X支持此功能.苹果股票Leopard python 2.5.1没有.

如果您还没有,则需要下载并安装MacPorts.仅供参考,我认为Porticus是围绕MacPorts的优秀GUI.

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

来自Apple的Leopard python(python 2.5.1) – 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>
>>> 

标签:python,macos,beanstalkd
来源: https://codeday.me/bug/20190726/1548282.html