Problem with multithreading

Jeffrey Barish jeff_barish at earthlink.net
Thu Jun 25 00:09:44 EDT 2009


Jeffrey Barish wrote:

> I have a program that uses multithreading to monitor two loops.  When
> something happens in loop1, it sends a message to loop2 to have it execute
> a command.  loop2 might have to return a result.  If it does, it puts the
> result in a queue.  loop1, meanwhile, would have blocked waiting for
> something to appear in the queue.  The program works for a while, but
> eventually freezes.  I know that freezing is a sign of deadlock.  However,
> I put in print statements to localize the problem and discovered something
> weird.  The freeze always occurs at a point in the code with the following
> statements:
> 
> print "about to try"
> try:
>     print "in try"
>     <do something>
> 
> I get "about to try", but not "in try".  Is this observation consistent
> with
> the deadlock theory?  If not, what could be making the program freeze at
> the try statement?  I wrote a test program using the same techniques to
> illustrate the problem, but the test program works perfectly.  I could
> post it, though, if it would help to understand what I am doing -- and
> what might be wrong in the real program.

As I ponder this problem, I am beginning to believe that the problem is not
related to multithreading.  If the problem were due to a collision between
the two threads then timing would matter, yet I find that the program
always freezes at exactly the same statement (which executes perfectly
hundreds of times before the freeze).  Moreover, the test program that I
wrote to test the multithreading implementation works perfectly. And
finally, there is nothing going on related to multithreading at this point
in the code.  Why else might the program freeze at a try statement?
-- 
Jeffrey Barish




More information about the Python-list mailing list