代码拉取完成,页面将自动刷新
#之前的作业回顾:
#1)多线程中的线程任务,是否可以开启新的线程或进程
#2)多进程中的进程任务,是否可以开启新的线程或进程
import os
import time
from concurrent.futures import ThreadPoolExecutor, ProcessPoolExecutor
def task():
print(task.__module__, task.__name__)
pid = os.getpid()
print(f'This is task, pid is {pid}')
time.sleep(1)
def create_thread_pool():
with ThreadPoolExecutor(20) as executor:
executor.submit(task)
def create_process_pool():
with ProcessPoolExecutor(7) as executor:
executor.submit(task)
###进程池创建线程
def test1_process_create_thread_pool():
with ProcessPoolExecutor(7) as executor:
executor.submit(create_thread_pool)
###进程池创建进程
def test2_process_create_thread_pool():
with ProcessPoolExecutor(7) as executor:
executor.submit(create_process_pool)
###线程池创建线程
def test3_thread_create_thread_pool():
with ThreadPoolExecutor(20) as executor:
executor.submit(create_thread_pool)
###线程池创建进程
def test4_thread_create_process_pool():
with ThreadPoolExecutor(20) as executor:
executor.submit(create_process_pool)
if __name__ == '__main__':
test1_process_create_thread_pool()
test2_process_create_thread_pool()
test3_thread_create_thread_pool()
test4_thread_create_process_pool()
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。