Is the standard output thread-safe?

Fredrik Lundh fredrik at pythonware.com
Thu Mar 9 11:27:44 EST 2006


Fernando Rodríguez wrote:

> Is the standard output thread-safe? Can I use print from several threads
> without having to use a mutex?

if you use sys.stdout.write on the standard sys.stdout stream, each write
operation is "atomic" (thanks to the GIL).

if you use other approaches (including print statements, or sys.stdout re-
direction via python code), data from different streams may appear out of
order.  python won't crash, though.

</F>






More information about the Python-list mailing list