simple Thread question

Dave Brueck dave at
Tue Aug 3 22:24:15 CEST 2004

Christopher T King wrote:

> On 3 Aug 2004, adeger wrote:
>>Having trouble with my first forays into threads.  Basically, the
>>threads don't seem to be working in parallel (or you might say are
>>blocking).  I've boiled my problems to the following short code block
>>and ensuing output.  Seems like the output should be all interleaved
>>and of course it's not.  Running Python 2.2 from ActiveState on
>>Windows XP (also doesn't work on Windows 2000).
> The Python interpreter isn't too thread-friendly.  Because it's not 
> re-entrant, it has to make use of a Global Interpreter Lock in order to 
> keep internal structures from getting mangled.  This lock only allows one 
> thread to access the interpreter at a time, and switches threads every 
> hundred or so bytecodes.  The likely cause of your problem is that your 
> loops don't reach this switching threshold -- try using xrange(100) or 
> higher.

Er... you're jumping the gun a bit - no need to scare the OP away from 
threads with all these details about the GIL when the problem was simply 
that the threads were never started.

> Because of the former property, another thing you can try is 
> inserting a time.sleep(.1) inside of each loop

Uh, did you read his code before responding? (hint: he's already doing 
that) :)


More information about the Python-list mailing list