Python正确使用池的方法apply_async

时间:2018-11-29 18:40:08

标签: multithreading python-2.7 threadpool

我是python多线程编程的新手,目前我想创建一个worker并打印消息,我使用以下代码:

def worker_main(msg):
   print 'success'
   print "{0} retrieved: {1}".format(getpid(), msg)
   sleep(1)


if __name__ == '__main__':
    pool = Pool(5)
    for i in range(50):
        print i
        pool.apply_async(worker_main, ("First item for loop %d" % i))

目前,它仅显示i,但不运行worker_main,有人知道为什么吗? 谢谢

0 个答案:

没有答案