python 中threading的运用
来源:互联网 发布:马尔科夫转移矩阵 编辑:程序博客网 时间:2024/05/19 23:16
#coding = utf-8
import threading
from time import sleep,ctime
loops = [4,2]
def loop(nloop, nsec):
print 'start loop', nloop, 'at:', ctime()
sleep(nsec)
print 'loop', nloop, 'done at:', ctime()
def main():
#输出starting表示开始,并输出开始时间
print 'starting at:',ctime()
#建立一个空数组,存储
threads = []
nloops = range(len(loops))
#创建线程
for i in nloops:
t = threading.Thread(target = loop,args=(i,loops[i]))
threads.append(t)
#开始线程
for i in nloops:
#start()开始线程活动
threads[i].start()
#等待所有线程结束
for i in nloops:
#join等待线程终止
threads[i].join()
#输出最后时间
print 'all end:',ctime()
if __name__ == '__main__':
main()
import threading
from time import sleep,ctime
loops = [4,2]
def loop(nloop, nsec):
print 'start loop', nloop, 'at:', ctime()
sleep(nsec)
print 'loop', nloop, 'done at:', ctime()
def main():
#输出starting表示开始,并输出开始时间
print 'starting at:',ctime()
#建立一个空数组,存储
threads = []
nloops = range(len(loops))
#创建线程
for i in nloops:
t = threading.Thread(target = loop,args=(i,loops[i]))
threads.append(t)
#开始线程
for i in nloops:
#start()开始线程活动
threads[i].start()
#等待所有线程结束
for i in nloops:
#join等待线程终止
threads[i].join()
#输出最后时间
print 'all end:',ctime()
if __name__ == '__main__':
main()
阅读全文
0 0
- python 中threading的运用
- python的多线程运用Threading
- python的threading模块中threading.RLock和threading.Lock
- Python中threading的问题
- Python中threading模块的join函数
- Python中Threading.Join的案例解析
- Python的threading模块
- python threading的学习
- python中threading模块详解
- python中threading模块详解
- Python中threading.local方法
- python中threading模块详解
- python中threading模块详解
- python中threading的常用方法的详解
- Python中使用threading.Event协调线程的运行
- Python中多线程thread与threading的实现方法
- python中threading的高级函数应用解析
- python中continue的运用
- 2017.07.16日C组模拟赛总结
- hdu 6053 莫比乌斯反演函数的利用 2017 Multi-University Training Contest
- LintCode Guess Number Game II
- 从零单排-python-01
- 第一次做的爬虫
- python 中threading的运用
- math库和random库
- HDU 6055 Regular polygon(几何)
- 可以在 JavaScript 中创建三种消息框:警告框、确认框、提示框。
- 1009. 说反话 (20)
- LeetCode 455 Assign Cookies
- android 与Java后台交互
- 无线传感网技术学习
- Mysql 基础操作