Execute code after death of all child processes - (corrected posting)

Jeff Epler jepler at unpythonic.net
Sat Dec 25 15:20:24 CET 2004

First, you'll want to exit from each forked copy, or else it will reach
the code-after-the-for-loop:
    import sys, os, time
    texts = ['this is text1', 'this is text 2']
    for current_text in texts[0:]:
        pid = os.fork()
        if pid == 0:
            print current_text
            raise SystemExit

Next, you'll want to wait for each process you started:
    for current_text in texts:
        os.waitpid(-1, 0)
    print 'this is the end'

$ python /tmp/franz.py 
this is text1
this is text 2
this is the end

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 196 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/python-list/attachments/20041225/1835e3b9/attachment.pgp>

More information about the Python-list mailing list