赞
踩
- from multiprocessing import Pool
- import os
- import time
- import random
-
-
- def long_time_task(name):
- print('Run task %s (%s)...' % (name, os.getpid()))
- start = time.time()
- time.sleep(random.random() * 3)
- end = time.time()
- print('Task %s runs %0.2f seconds.' % (name, (end - start)))
-
- if __name__ == '__main__':
- print('Parent process %s.' % os.getpid())
- p = Pool(4)
- for i in range(5):
- p.apply_async(long_time_task, args=(i,))
- print('Waiting for all subprocesses done...')
- p.close()
- p.join()
- print('All subprocesses done.')
表现:程序编译错误,显示无法引入相关模块。
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。