AttributeError:队列实例没有属性“_empty”;
一位客户在使用我的使用 Python 2.5.5 的软件时遇到了此错误。怎么可能呢? _empty 是否已从队列中消失?我完全不明白这一点。我没有继承自queue,只有Queue类的一个普通实例。在我的机器上一切似乎都工作正常,但是在客户的机器上出现了错误。谁能给我一些建议可能是什么问题?
问题就发生在这里:
import Queue
self.requests.mutex.acquire()
allCount = self.requests._qsize()
while not self.requests._empty():
try:
(sock, addr, _) = self.requests._get()
# ... do some things
self.requests.mutex.release()
之前,队列是用 初始化的
self.requests = Queue(self.reqQLen)
并且模块中也使用了这些队列方法:put_nowait、qsize、get。队列在多线程上下文中使用。这可能是原因吗?
我想知道:错误消息告诉我变量 requests 被识别为队列实例,但属性 _empty 不存在。然而,这是 Queue 类中的普通方法。
A customer has got this error with my software using Python 2.5.5. How can it be? Does _empty has disappeared from the queue? I don't understand this at all. I did not inherit from queue, there is just a normal instance of the Queue class. On my machine all seems to work fine, however, on the machine of the customer the error came up. Can anyone give me some advice what the problem could be?
The problem has happened here:
import Queue
self.requests.mutex.acquire()
allCount = self.requests._qsize()
while not self.requests._empty():
try:
(sock, addr, _) = self.requests._get()
# ... do some things
self.requests.mutex.release()
Before, the queue was initialized with
self.requests = Queue(self.reqQLen)
And these queue methods are also used in the module: put_nowait, qsize, get. The queue is used in context of multi-threading. Could this be the cause?
I'm wondering: The error message tells me that the variable requests is recognized as a queue instance but the attribute _empty is not there. However, this is a normal method in the Queue class.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我对此不是很熟悉(而且我不知道你使用的是哪个版本的Python),但是看看 文档 我没有看到任何提及
_empty
属性,但只提到empty()
方法。由于前导下划线用于表示私有属性,因此在我看来,它的存在可能不是标准化的,而是依赖于实现的,并且使用empty()
方法将是正确的解决方案。I'm not very familiar with this (and I don't know what version of Python you are using), but looking at the documentation I see no mention of an
_empty
attribute, but only anempty()
method. Since the leading underscore is used to denote private attributes, it seems likely to me that its existence is not standardized but is implementation-dependent, and that using theempty()
method instead would be the correct solution.