tag:blogger.com,1999:blog-5440028356946346379.post202837889822578878..comments2007-05-07T15:54:17.372-04:00Comments on Doug Hellmann: PyMOTW: QueueDoug Hellmannhttp://www.blogger.com/profile/01892352754222143463noreply@blogger.comBlogger2125tag:blogger.com,1999:blog-5440028356946346379.post-43135342769610035582007-05-07T15:54:00.000-04:002007-05-07T15:54:00.000-04:00Ah, that's true. I'm sorry I didn't make that cle...Ah, that's true. I'm sorry I didn't make that clear. The queue module was added in 1.4, and the API was later changed as you point out. I was working with 2.5 when I wrote the tutorial.<BR/><BR/>If you're working with a version of Python that does not have join(), you can simulated it by looping around a call to empty() followed by a sleep if the queue is not empty. That only tells you when the queue is empty, though, and not when each item is actually done processing. <BR/><BR/>If each worker thread uses a non-blocking call to get() with some reasonable timeout, you should be able to then detect the empty queue and return from the thread. That would, in turn, let you join() the worker threads at the end of your main thread to ensure they had a chance to finish the last task before your app exits.<BR/><BR/>Obviously it is a lot simpler and more reliable using the new Queue methods join() and task_done(). :-)Doughttp://www.blogger.com/profile/01892352754222143463noreply@blogger.comtag:blogger.com,1999:blog-5440028356946346379.post-13679607789428039812007-05-07T15:40:00.000-04:002007-05-07T15:40:00.000-04:00Nice tutorial. One minor detail: The methods join(...Nice tutorial. <BR/><BR/>One minor detail: The methods join() and task_done() of the Queue object appeared in Python 2.5, so you need at least this version if you want to run the code (not 1.4 as indicated at the beginning). I knew about the Queue module already, but not about these two helpful additions. Thanks for the hint. :)Anonymousnoreply@blogger.com