# -*- coding:utf-8 -*-
#以下代码都是以上一篇为基础做整理的,使得代码更为简洁,减少冗余
#在IDLE编辑器下运行
# 改进第一版
#-------------------------------------------------------------
# import time
# import thread
#
# def loop(nloop,nsec):
# print("loop%s start at :"%nloop,time.ctime())
# time.sleep(nsec)
# print("loop%s stop at :"%nloop,time.ctime())
#
#
# def main():
# print ('all start at :',time.ctime())
# sleep_list = [4,2]
# for i in range(2):
# thread.start_new_thread(loop,(i,sleep_list[i]))
# time.sleep(5)
# print ('all stop at :',time.ctime())
#
# if __name__ =="__main__":
# main()
#继续在这之上改进,使得程序更加灵活,第二版
#-------------------------------------------------------------
import time
import thread
def loop(nloop,nsec):
print("loop%s start at :"%nloop,time.ctime())
time.sleep(nsec)
print("loop%s stop at :"%nloop,time.ctime())
def main():
print ('all start at :',time.ctime())
sleep_list = [4,2,2,3,1,2]
for i in range(len(sleep_list)):
thread.start_new_thread(loop,(i,sleep_list[i]))
time.sleep(max(sleep_list)+1)
print ('all stop at :',time.ctime())
if __name__ =="__main__":
main()
线程(二):在first的基础上对代码作修改,使得代码冗余更少,更灵活
猜你喜欢
转载自blog.csdn.net/a_lazy_zhu/article/details/80192968
今日推荐
周排行