Processes and their childs

Discussion in 'Python' started by Markus Franz, Dec 21, 2004.

  1. Markus Franz

    Markus Franz Guest

    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
    Markus Franz, Dec 21, 2004
    #1
    1. Advertising

  2. Markus Franz

    Jeff Epler Guest

    "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-----
    Jeff Epler, Dec 21, 2004
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. -H
    Replies:
    3
    Views:
    350
    Jack Klein
    Aug 19, 2003
  2. Guillermo D. Polonsky

    Keep javascript reference to the childs

    Guillermo D. Polonsky, Jul 11, 2006, in forum: ASP .Net
    Replies:
    2
    Views:
    403
    =?ISO-8859-1?Q?G=F6ran_Andersson?=
    Jul 11, 2006
  3. -H

    teeing parent+childs output

    -H, Aug 18, 2003, in forum: C Programming
    Replies:
    3
    Views:
    314
    Jack Klein
    Aug 19, 2003
  4. Yoav
    Replies:
    1
    Views:
    269
    Diez B. Roggisch
    Aug 22, 2005
  5. Replies:
    2
    Views:
    433
    Chris Uppal
    Sep 19, 2006
Loading...

Share This Page