Do something simlar by forking process instead of threads : System fork « System « Python






Do something simlar by forking process instead of threads

import os, sys

def counter(count):
    for i in range(count): print '[%s] => %s' % (os.getpid(), i)

for i in range(10):
    pid = os.fork()
    if pid != 0:
        print 'Process %d spawned' % pid
    else:
        counter(100)
        sys.exit()

print 'Main process exiting.'

           
       








Related examples in the same category