from concurrent.futures import ThreadPoolExecutor, ProcessPoolExecutor
# 线程池
# def target(url):
# print(url)
# def main():
# # 创建线程池
# with ThreadPoolExecutor(30) as t:
# for url in range(100):
# t.submit(target, url)
# # 主线程等待线程池所有线程执行完成
# print("主线程...")
# 进程池
def target(url):
print(url)
def main():
# 创建进程池
with ProcessPoolExecutor(30) as t:
for url in range(1000):
t.submit(target, url)
# 主进程等待线程池所有进程执行完成
print("主进程...")
if __name__ == "__main__":
main()
python进程池和线程池
原创wx5ff1414e56729 博主文章分类:python多任务编程 ©著作权
©著作权归作者所有:来自51CTO博客作者wx5ff1414e56729的原创作品,请联系作者获取转载授权,否则将追究法律责任
下一篇:python实现多线程

提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
Java 线程池 ThreadPoolExecutor
记录线程池的使用
线程池 java ide