AttributeError:队列实例没有属性“_empty”;

发布于 2024-10-21 05:11:09 字数 659 浏览 6 评论 0原文

一位客户在使用我的使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

醉殇 2024-10-28 05:11:09

我对此不是很熟悉(而且我不知道你使用的是哪个版本的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 an empty() 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 the empty() method instead would be the correct solution.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文