'''多进程多线程学习1'''
import math,time
import datetime
from concurrent.futures import ThreadPoolExecutor,ProcessPoolExecutor
#线程的执行方法
def print_value(value):
print('thread'+str(value),' ',int(str(datetime.datetime.now()).split('.')[-1])) #线程与时间
def my_thread(value):#每个进程里面设置线程
# 如果不填写max_workers=2,就会根据计算机的每一个CPU创建一个进程,如果四核就创建四个进程
thread=ThreadPoolExecutor(max_workers=5)
thread.submit(print_value,value) #函数与传入的参数值
thread.submit(print_value,value)
thread.submit(print_value, value)
thread.submit(print_value, value)
thread.submit(print_value, value)
def my_process():#进程
pool=ProcessPoolExecutor(max_workers=2)#进程池
#创建两个进程,每个进程执行my_thread方法,my_thread主要将每个进程通过线程执行,
pool.submit(my_thread,int(str(datetime.datetime.now()).split('.')[-1])) #提交,线程方法与值
time.sleep(0.1)
pool.submit(my_thread,datetime.datetime.now())
if __name__=='__main__':
my_process()