from time import ctime,sleep
import multiprocessing #导入进程相关的模块
#定义说和写的方法
def talk(content,loop):
for i in range(loop):
print('start talk:{}{}'.format(content,ctime()))
sleep(2)
def write(content,loop):
for i in range(loop):
print('start write:{}{}'.format(content,ctime()))
sleep(3)
#定义和加载说和写的进程
process = [] #装载进程
t1=multiprocessing.Process(target=talk,args=('speak:hello world',2))
process.append(t1)
t2=multiprocessing.Process(target=write,args=('write:life is short you need python',2))
process.append(t2)
if __name__ == "__main__":
for t in process:
t.start()
for t in process:
t.join()
print('all the end %s'%ctime())
转载于:https://www.cnblogs.com/Luafair/p/9993608.html