Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Item 39, Page 134: ClosableQueue close() method #18

Closed
dgolden1 opened this issue Apr 27, 2015 · 2 comments
Closed

Item 39, Page 134: ClosableQueue close() method #18

dgolden1 opened this issue Apr 27, 2015 · 2 comments
Labels

Comments

@dgolden1
Copy link

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!

@bslatkin
Copy link
Owner

bslatkin commented Apr 27, 2015 via email

@bslatkin
Copy link
Owner

bslatkin commented Oct 3, 2015

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.

@bslatkin bslatkin closed this as completed Oct 3, 2015
@bslatkin bslatkin added the 1ed First Edition label Aug 7, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants