Reputation: 653
How can i fetch the data returned by worker here??
import multiprocessing
def worker():
"""worker function"""
return 'DATA'
if __name__ == '__main__':
jobs = []
for i in range(5):
p = multiprocessing.Process(target=worker)
print p
jobs.append(p)
p.start()
OUTPUT :
DATA
DATA
DATA
DATA
DATA
Upvotes: 1
Views: 94
Reputation: 298166
You can make a pool of workers and pass in some data to process:
import multiprocessing
def worker(item):
return item ** 2
if __name__ == '__main__':
pool = multiprocessing.Pool(5)
for result in pool.imap_unordered(worker, range(30)):
print result
Upvotes: 1