1

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
4

1 回答 1

1

您可以创建一个工人池并传入一些数据进行处理:

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
于 2013-04-19T07:38:00.890 回答