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.
added test script and expected output file as well
this closes patch 103297.
__all__ attributes will be added to other modules without first submitting
a patch, just adding the necessary line to the test script to verify
more-or-less correct implementation.
1. Comments at the beginning of the module, before
functions, and before classes have been turned
into docstrings.
2. Tabs are normalized to four spaces.
Also, removed the "remove" function from dircmp.py, which reimplements
list.remove() (it must have been very old).
+ Implements a put_nowait method.
+ Adds a corresponding Queue.Full exception.
+ Simplifies the implementation by adding optional "block" args to get() and
put(), and makes the old get_nowait() and new put_nowait() one-line
redirections to get() and put().
+ Uses (much) simpler logic for the nowait cases.
+ Regularizes the doc strings to something closer to "Guido style" <wink>.
+ Converts two stray tabs into spaces.
+ Removes confusing verbiage about the queue "not being available" from the
docstrings -- never knew what that meant as a user, and after digging into
the implementation still didn't know what it was trying to say.
class from the standard base exception Exception. Otherwise define
Queue.Empty as a string exception.
(Queue): 8-space to 4-space indentation conversion. Also, basically
recast all method comments into docstrings.
constructors. There is no backward compatibility. Not everything has
been tested.
* aiff.{py,doc}: deleted in favor of aifc.py (which contains its docs as
comments)