Is the standard output thread-safe?

  • Thread starter =?iso-8859-1?Q?Fernando=20Rodr=edguez?=
  • Start date
?

=?iso-8859-1?Q?Fernando=20Rodr=edguez?=

Hi,

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

Thanks
 
F

Fredrik Lundh

Fernando said:
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>
 
?

=?iso-8859-1?Q?Fernando=20Rodr=edguez?=

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

GIL?
 
F

Felipe Almeida Lessa

Em Qui, 2006-03-09 às 16:37 +0000, Fernando Rodríguez escreveu:
Hello Fredrik,


GIL?

Global Interpreter Lock

--
"Quem excele em empregar a força militar subjulga os exércitos dos
outros povos sem travar batalha, toma cidades fortificadas dos outros
povos sem as atacar e destrói os estados dos outros povos sem lutas
prolongadas. Deve lutar sob o Céu com o propósito primordial da
'preservação'. Desse modo suas armas não se embotarão, e os ganhos
poderão ser preservados. Essa é a estratégia para planejar ofensivas."

-- Sun Tzu, em "A arte da guerra"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,289
Messages
2,571,448
Members
48,126
Latest member
ToneyChun2

Latest Threads

Top