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

Python模块学习------ 多线程

时间:2017-07-05 21:05:40      阅读:159      评论:0      收藏:0      [点我收藏+]

标签:width   sleep   time   highlight   targe   style   start   pen   target   

# 创建一个Thread实例,传给它一个函数;

import threading from time import sleep, ctime loops = [4,2] def loop(nloop, nsec): print "start loop", nloop, "at:",ctime() sleep(nsec) print "end loop", nloop, "at:",ctime() def main(): print "*****start*********", ctime() threads = [] nloops = range(len(loops)) for i in nloops: t = threading.Thread(target=loop, args=(i, loops[i])) threads.append(t) # start threads for i in nloops: threads[i].start() # wait for all threads to finish for i in nloops: threads[i].join() print "*******end*******", ctime() if __name__ == "__main__": main()

 

Python模块学习------ 多线程

标签:width   sleep   time   highlight   targe   style   start   pen   target   

原文地址:http://www.cnblogs.com/xiyuan2016/p/7123157.html

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