print in multithreaded environement ???
Josiah Carlson
jcarlson at nospam.uci.edu
Wed Feb 25 17:21:44 EST 2004
> Does sys.stdout is a seperate instance for each thread ?
> Does sys.stdout is shared between all of them ?
sys.stdout, sys.stdin and sys.stderr are all shared.
> Does any one has experience with that ?
Yes. As soon as a thread uses up its timeslice, it is paused. Sending
a lot of information to sys.stdout, or doing any non-trivial computation
is a good way of using up a timeslice...as is sleeping for an
arbitrarily small amount of time, even 0.
Run the following code to see how it behaves.
import time
from threading import Thread
def funct(i):
for j in xrange(50):
print i,
time.sleep(0)
for i in xrange(50): Thread(target=funct, args=(i,)).start()
- Josiah
More information about the Python-list
mailing list