Multi-threaded printing and UIErrors in Windows

David Fraser davidf at sjsoft.com
Fri Apr 23 02:27:22 EDT 2004


Roger Binns wrote:
> My program has a random smattering of print statements
> scattered throughout that are mainly a debugging aid.
> They are typically things like this:
> 
>     print "entering key mode"
> 
> The code is multithreaded, and the printing typically
> happens in both the main thread and a worker thread
> doing serial port IO.  The problem I am experiencing
> when the program is packaged up with py2exe is that
> exceptions happen:
> 
>   IOError: [Errno 9] Bad file descriptor
> 
> This can happen in either thread.  Why is this
> happening?  It doesn't happen on Linux or Mac,
> and hasn't happened when not using py2exe.
> 
> Python 2.3, wxPython 2.4, py2exe 0.5 (and the
> previous version).
> 
> Roger
> 
> 
sys.stdout is not threadsafe - try wrapping each call with a mutext and 
see if that fixes it...



More information about the Python-list mailing list