[Python-Dev] Queue.Queue guts replaced (original) (raw)
Tim Peters tim.one at comcast.net
Mon Jul 12 03:00:16 CEST 2004
- Previous message: [Python-Dev] More joy with test_strptime
- Next message: [Python-Dev] PyInstance_Check() and new-style classes
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Here's the checkin comment. Note the last item: I haven't done comparative timings, because I don't care. If you do, feel encouraged. I can't be convinced to care even if it's 10x slower than before, so if it is, complain here and get a constituency if you care enough to re-obfuscate it.
""" Bug #788520: Queue class has logic error when non-blocking
I don't agree it had a bug (see the report), so this is not a candidate for backporting, but the docs were confusing and the Queue implementation was old enough to vote.
Rewrote put/put_nowait/get/get_nowait from scratch, to use a pair of Conditions (not_full and not_empty), sharing a common mutex. The code is 1/4 the size now, and 6.25x easier to understand. For blocking with timeout, we also get to reuse (indirectly) the tedious timeout code from threading.Condition. The Full and Empty exceptions raised by non-blocking calls are now easy (instead of nearly impossible) to explain truthfully: Full is raised if and only if the Queue truly is full when the non-blocking put call checks the queue size, and similarly for Empty versus non-blocking get.
What I don't know is whether the new implementation is slower (or faster) than the old one. I don't really care. Anyone who cares a lot is encouraged to check that. """
- Previous message: [Python-Dev] More joy with test_strptime
- Next message: [Python-Dev] PyInstance_Check() and new-style classes
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]