You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This isn't an error in your book but more of a gotcha; you define the ClosableQueue class as a subclass for Queue.Queue (I'm using Python 2.7 here); ClosableQueue implements a close() method to inform queue consumers that no more items will be added to the queue. This is totally fine with Queue.Queue, but if you want to take it to the next level with multiprocessing.Queue, you encounter an unexpected problem because multiprocessing.Queue already implements a close() method that does something different:
Indicate that no more data will be put on this queue by the current process. The background thread will quit once it has flushed all buffered data to the pipe. This is called automatically when the queue is garbage collected.
As an unwitting user, I subclassed ClosableQueue from multiprocessing.Queue, which resulted in the base class close() method being overwritten -- not what I wanted!
You may want to add that caveat to the book or consider changing the ClosableQueue name to something like FinalizableQueue.
P.S.
Loved the book!
The text was updated successfully, but these errors were encountered:
Thanks for the report. Seems like a good suggestion. Let me reproduce the
problem and then I'll reply on this thread. Happy to hear you liked the
book!
I've thought about this. I'd like to keep this simple. I think most users shouldn't touch multiprocessing.Queue, they should use a ProcessPoolExecutor instead. I'm going to leave this as it is in the book.
This isn't an error in your book but more of a gotcha; you define the
ClosableQueue
class as a subclass forQueue.Queue
(I'm using Python 2.7 here);ClosableQueue
implements aclose()
method to inform queue consumers that no more items will be added to the queue. This is totally fine withQueue.Queue
, but if you want to take it to the next level withmultiprocessing.Queue
, you encounter an unexpected problem becausemultiprocessing.Queue
already implements aclose()
method that does something different:As an unwitting user, I subclassed
ClosableQueue
frommultiprocessing.Queue
, which resulted in the base classclose()
method being overwritten -- not what I wanted!You may want to add that caveat to the book or consider changing the
ClosableQueue
name to something likeFinalizableQueue
.P.S.
Loved the book!
The text was updated successfully, but these errors were encountered: