[Tutor] os.fork | queue

Jojo Mwebaze jojo.mwebaze at gmail.com
Thu Apr 1 23:34:53 CEST 2010

I am trying to implement parallel processing with os.fork.. However i want
to collect results from each process.. I thought i could use Queues, but i
cant seem to get it work. Threading, can not work for me, because of the way
some functions have been written -

Below is a copy of what i had written..



import os, time, Queue
import do_something

mylist1 = [item1, item2, item3 ......]
mylist2 = [item1,item2, item2 ......]

def child(x, y):
    return do_something(x,y)

def parent(myqueue):
    for x, y in zip (mylist1, mylist2):

         pid = os.fork()

         if pid !=0:
              print 'Process %d spwaned' %pid
             result = child(x, y)
    return myqueue

myqueue = Queue.Queue(0)
data = parent(myqueue)

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20100401/f46c36e6/attachment.html>

More information about the Tutor mailing list