By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,576 Members | 1,360 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,576 IT Pros & Developers. It's quick & easy.

Processes and their childs

P: n/a
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
Jul 18 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
"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-----

Jul 18 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.