This repository has been archived by the owner on Oct 26, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Prevent Queue.qsize() from raising NotImplementedError on Mac OS X
multiprocessing.Queue.qsize() may raise NotImplementedError on Unix platforms like Mac OS X where sem_getvalue() is not implemented. In order to address this problem, subclass Queue and use an internal synchronized shared counter whose value is updated when the put() and get() methods are called. As a side benefit, this makes it possible to have a reliable version of both qsize() and empty(). Thanks to Jean-Baptiste Marquette for reporting this problem (#11). This merges branch 'fix-Queue.qsize-NotImplementedError'
- Loading branch information
Showing
6 changed files
with
71 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9ca6b4b
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this workaround helped me a lot, thanks for that.
In my case I had to adjust the code as follows.
`class Queue(multiprocessing.queues.Queue):
"""
Important changes:
9ca6b4b
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Happy to hear it was useful, @johcode!
Would you like to send a pull request? (so that the code works in both Python 2 and 3).
This was fixed by @dchecks in #103.
I think that's the case already: we do
not self.qsize()
— the truth value of 0 is False, so that would return True. For all the other numbers, their truth value is True, which becomes False when we negate it.