进程、线程、协程开启方式
标签:线程pidblog一个false进程defthreadingbody
__author__ = ‘admin‘
from gevent import monkey
monkey.patch_all(thread=False)
import gevent,time,os
from threading import Thread,currentThread
from multiprocessing import Process,Pool,current_process
from concurrent.futures import ProcessPoolExecutor,ThreadPoolExecutor
def thread_fun(item):
print(‘\\033[33m <name:%s> <value:%s> <pid:%s> start…‘%(currentThread().name,item,os.getpid()))
time.sleep(1)
print(‘\\033[33m <name:%s> <value:%s> <pid:%s> end…‘%(currentThread().name,item,os.getpid()))
def process_fun(item):
print(‘\\033[35m <name:%s> <value:%s> <pid:%s> start…‘%(current_process().name,item,os.getpid()))
time.sleep(1)
print(‘\\033[35m <name:%s> <value:%s> <pid:%s> start…‘%(current_process().name,item,os.getpid()))
def gevent_fun(item):
print(‘\\033[36m <name:%s> <value:%s> <pid:%s> start…‘%(currentThread().name,item,os.getpid()))
time.sleep(1)
print(‘\\033[36m <name:%s> <value:%s> <pid:%s> end…‘%(currentThread().name,item,os.getpid()))
return item**2
def thread_pool_fun(item):
print(‘\\033[32m <name:%s> <value:%s> <pid:%s> start…‘%(currentThread().name,item,os.getpid()))
time.sleep(1)
print(‘\\033[32m <name:%s> <value:%s> <pid:%s> end…‘%(currentThread().name,item,os.getpid()))
return item**2
def thread_pool_fun_callback(item):
print(‘\\033[31m <name:%s> <value:%s> <pid:%s> start…‘%(currentThread().name,item,os.getpid()))
time.sleep(1)
print