Processes and their childs

M

Markus Franz

Hi!


Inside a Python script (I use Python 2.4) several different child
processes are created by using os.fork().

My problem: I want only the parent process to print some output and
then create the child processes. But even If I use print BEFORE using
os.fork, everything that was printed by the parent process untill this
point is printed by every child process again. How can I avoid this?

Does anybody habe a solution for my problem???
Thanks.


Markus
 
J

Jeff Epler

"flush" your files before forking.

For me, this program gives the correct output 'hello\n' when correct=1.
When correct=0, I get either 'hello\nhello' or 'hellohello\n' as output.

------------------------------------------------------------------------
correct = 0
import sys, os
sys.stdout.write('hello')
if correct: sys.stdout.flush()
if os.fork() == 0: sys.stdout.write('\n')
------------------------------------------------------------------------

Jeff

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.1 (GNU/Linux)

iD8DBQFByDIYJd01MZaTXX0RAhdOAKCgxWumyXJ+583mXPfzI/vGYCVNoQCfZnPI
aeqU092Hi8845yEAe8TfABw=
=GX5i
-----END PGP SIGNATURE-----
 

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

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top