473,320 Members | 2,162 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Is the standard output thread-safe?


Hi,

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

Thanks
Mar 9 '06 #1
5 8507
>Is the standard output thread-safe?
No.

You'll need to synchronize access.

Mar 9 '06 #2
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>

Mar 9 '06 #3
Hello Fredrik,
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).


GIL?
Mar 9 '06 #4
Em Qui, 2006-03-09 Ã*s 16:37 +0000, Fernando RodrÃ*guez escreveu:
Hello Fredrik,
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).


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"

Mar 9 '06 #5
Fernando Rodríguez <fr*@easyjob.net> writes:
Hi,

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

Thanks


Check this: http://me.in-berlin.de/doc/python/fa...re-thread-safe

from my experience, it seems 'print' is not thread-safe. especially
when it is called with formated string, such as:

print "id:%d", my_id

I think it is not an "atomic" operation.

--
Mar 12 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Grzegorz | last post by:
Hello, I'm using eclipse with pydev plugin, I'm working on a program using wxpython . When I'm executing that application standard error output does not show in eclipse console window - wxpython...
1
by: Dirk Reske | last post by:
Hello, when I start a console app manually I get the output into the console. But when I start it with my application and read the standardOutput (which is redirected), I get nothing? It works...
3
by: Bo | last post by:
In my asp.net webservice application, I need to launch a DOS process as authorized users. To impersonate users, I use <impersonation = true> in my webconfig. I can't use Diagnostics.Process.Start,...
2
by: Brian | last post by:
I'm running a dos program via System.Diagnostics.Process. The dos program is very picky about filenames and such, and so I want to show the output to the user so they can verify it did what it...
6
by: Alan Wang | last post by:
Hi All, My application puts standard output from command line(using process.start()) into a file on the hard disk then reads the info from that file after command has finished. The problem is...
16
by: Zenon | last post by:
I have an application where I create a Plink process to communicate with an HP Unix box. The problem I am having is that while reading the redirected output, it seems to try to continue past the...
3
by: beliavsky | last post by:
I want to write a function that writes to an output file if specified and otherwise to standard output. How can I connect a file object to standard output in the code below? I could use an if...
2
by: Devine123 | last post by:
Hi, I’m creating a perl script that takes incoming http/s requests, logs the standard input, output and error, before returning the output to the client. The input, output and error log is appended...
14
by: =?Utf-8?B?R2lkaQ==?= | last post by:
Hi, In my windows applicationm, i need to excute a batch file. this batch file throws some text and questions to the screen, i need to catch the standard Output, check if it's a question, in...
1
by: TP | last post by:
Hi everybody, I try to find a quick way to redirect the standard output of a Python command (for example: print "message") to a python variable "foobar". Ok, in this simple example, I could do...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.