[Python-Dev] Can someone look at dummy_thread (#622537)?

Brett Cannon brett@python.org
Fri, 29 Nov 2002 20:17:35 -0800 (PST)

There is a slight chance some of you remember the discussion that Zack
Weinberg brought up here back in September about his experiences in
rewriting ``tempfile``.  One of the things he brought up was having to
write his own fake lock so that the code would work when ``thread`` was
not available.  Guido suggested writing a module called ``dummy_thread``
that was API compatible with ``thread`` but was available on all
platforms; he said he would check it in if it was written.

Well, I wrote it. But  Guido has told me that he is too busy to check it
in and so I am emailing you guys to see if someone can look at it and
check it in.  I would like to get it in before 2.3a so as to get the extra
testing the alpha will get.

The  patch is #622537 ( http://www.python.org/sf/622537 ).  It is complete
to the best of my abilities.  I have docs and the module and the tests and
such.  Should be pretty straight-forward to apply assuming I didn't muck
up the docs (first attempt at doing any docs from scratch).

The only thing beyond quality of code and documentation that might have to
be dealt with is how far to integrate ``dummy_thread`` into the stdlib.
I have a patch to have ``Queue``, ``threading``, and ``tempfile`` all use
``dummy_thread`` when ``thread`` is not available.  Now I tested all of
them with and without ``thread`` available and they all pass.  But of
course I wonder if this will break any code.

The problem is that since ``dummy_thread`` basically just executes thread
calls serially there is a problem when sommething like blocking I/O is
used that blocks waiting for another thread (test_asynchat and test_socket
do that, but they require ``thread`` so there is no issue there outright).
So there is a chance that some code, when trying to run using
``threading`` will lock up.

But I don't think this is an issue.  I say in the docs that if you want to
guarantee true threading to run ``import thread; del thread`` before
importing ``threading``.  But the main reason I don't think it will be an
issue is that all other code that runs fine (but slowly) using
``dummy_thread`` now can be run where threads are not available.  And
those programs where deadlock would occur do not lose or gain anything
since they couldn't run on a platform without ``thread`` anyway.  The
only issue is that if they don't check for ``thread`` someone trying to
run the program will have a deadlocked program (although they shouldn't
have been trying to run it in the first place).

This is the only real questionable thing.  Obviously the module can be
checked in with no problem without touching the other modules (although
``Queue`` and ``tempfile`` should be patched regardless) if  this seems to
dicey to do.