1 Star 0 Fork 0

shong/lab-py

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
lab-thread.py 655 Bytes
一键复制 编辑 原始数据 按行查看 历史
shong 提交于 2017-07-21 08:33 . update
#!/usr/bin/env python
#-*- coding:utf-8 -*-
import threading
from time import sleep,ctime
loops = [4,2]
def loop(nloop,nsec):
print('start loop %s at %s ' % (nloop,ctime()))
sleep(nsec)
print('loop %s done at %s' % (nloop,ctime()))
def main():
print('starting at %s' % ctime())
threads = []
nloops = range(len(loops))
for i in nloops:
t = threading.Thread(target=loop,args=(i,nloops[i]))
threads.append(t)
for i in nloops:
threads[i].start()
for i in nloops:
threads[i].join()
print('all down at %s' % ctime())
if __name__=='__main__':
main()
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/shong/lab-py.git
git@gitee.com:shong/lab-py.git
shong
lab-py
lab-py
master

搜索帮助