python进程池和线程池
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()
浙公网安备 33010602011771号