0

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.

1
  • What version of Python are you and your customer running? Commented Mar 7, 2011 at 15:22

1 Answer 1

5

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.

Sign up to request clarification or add additional context in comments.

6 Comments

Version 2.5.5 is used. Using a private method should not be a problem, I think.
@Robert: Leading underscore shouts "If you use this and it changes/disappear, it's your fault". Private stuff is private exactly because nobody in the outside world should know of (let use) it.
So I have to expect that something removes the method in the Queue instance? Or can it be said that the error is a direkt proof that something has removed the method? The Queue implementation looks so innocent...
@Robert: You have to expect that something private changes behaviour, breaks backwards compability or gets removed completely (likely what happened here, but then again, it shouldn't matter) at any time. I.e. if you don't want you code to be locked down to one single release, you should stick to the public interface.
Reasonable advice, of course. I have adopted the source from my predecessor.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.