[Baypiggies] multithreading question

Alex Martelli aleax at google.com
Wed Sep 17 23:38:57 CEST 2008

On Wed, Sep 17, 2008 at 2:17 PM, Aahz <aahz at pythoncraft.com> wrote:
> On Wed, Sep 17, 2008, Shannon -jj Behrens wrote:
>> I know that threads are the devil and all, but I have a threading
>> question ;)
> What makes you say that threads are the devil?
>> 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?
> That depends really on the underlying OS library.  Mostly yes: a single
> Python C-level call to fwrite() will be atomic.  So technically, you're
> not counting on the GIL.  ;-)

I don't consider this reliable, in general: depending on the length of
data being written, writes on distributed filesystems such as NFS or
SMB are notoriously prone to NOT being atomic; how can I ensure that
stdout will never be redirected to a file living on such a filesystem,
for example?  IMHO, using the logging module or a dedicated
output-writing thread is well worth the (small) inconvenience.


More information about the Baypiggies mailing list