start function in new process

Jonathan Gardner jgardner at jonathangardner.net
Fri Mar 5 15:39:58 EST 2010


You're really close. See inline comment below.

On Fri, Mar 5, 2010 at 11:21 AM, wongjoekmeu at yahoo.com
<wongjoekmeu at yahoo.com> wrote:
>
> def c():
>    print "function c"
>
> def f(a,b, d):
>    # function I want to run in a new child process
>    print a, b
>    d()
>
> def g():
>    pidID = os.fork()
>    if pidID == 0:
>        # child do something here
>        f(2,3,c)

You'll need to exit here -- not return.
http://docs.python.org/library/os.html#os._exit

>    else:
>        # parent do something here
>        print "Parent
>
> for i in range(3):
>    g()
>

-- 
Jonathan Gardner
jgardner at jonathangardner.net



More information about the Python-list mailing list