python--再看并发之协程线程进程
Posted 拂髯客
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python--再看并发之协程线程进程相关的知识,希望对你有一定的参考价值。
多线程进行文件复制
import threading
import asyncio
import time
def copy(src,tar):
print('{} start...'.format(threading.current_thread().name))
with open(src,'rb') as binFileInputStream:
with open(tar,'wb') as binFileOutputStream:
binFileOutputStream.write(binFileInputStream.read())
time.sleep(10)
print('{} end...'.format(threading.current_thread().name))
threads = []
args = [('./test.py','./hella.py'),('./diabetes.csv','./diabetes.py')]
for i,arg in enumerate(args):
t = threading.Thread(target=copy,args=arg,name='thread-{}'.format(i))
threads.append(t)
for thread in threads:
thread.start()
for thread in threads:
thread.join()
以上是关于python--再看并发之协程线程进程的主要内容,如果未能解决你的问题,请参考以下文章