码迷,mamicode.com
首页 > 编程语言 > 详细

python--再看并发之协程线程进程

时间:2018-10-22 20:39:17      阅读:114      评论:0      收藏:0      [点我收藏+]

标签:join   线程进程   mat   threading   def   async   文件   print   tar   

多线程进行文件复制

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--再看并发之协程线程进程

标签:join   线程进程   mat   threading   def   async   文件   print   tar   

原文地址:https://www.cnblogs.com/Frank99/p/9831622.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!