[Baypiggies] multithreading question

Shannon -jj Behrens jjinux at gmail.com
Wed Sep 17 21:06:53 CEST 2008


On Wed, Sep 17, 2008 at 12:01 PM, Adam Hupp <adam at hupp.org> wrote:
> On Wed, Sep 17, 2008 at 11:40 AM, Shannon -jj Behrens <jjinux at gmail.com> wrote:
>>
>> I'm using the queue module to coordinate a bunch of threads.  Those
>> threads need to log a line to STDOUT.  The line is short.  Can I count
>> on the GIL to make sure that writing a single line to STDOUT is
>> atomic, or do I need to be more paranoid?
>
> Isn't the GIL dropped during any IO?  In that case I don't think you
> can rely on it.

Python gives up the GIL.  The C library goes to write the string.  It
writes out only four bytes.  A context switch occurs.  Some other
thread does the same thing.  Kaboom.

Seems plausible.  Is it really as bad as that?  Ugh.

-jj

-- 
Don't you wish you had a really clever sig like mine?
http://jjinux.blogspot.com/


More information about the Baypiggies mailing list