标签:reading read task rand target int map 执行 and
把线程都创建好,等待执行。
current_thread().getName()
获取当前线程的线程名
from threading import Thread,Semaphore,current_thread import time,random sm=Semaphore(5) def task(): with sm: print(‘%s 正在上厕所‘ %current_thread().getName()) time.sleep(random.randint(1,3)) if __name__ == ‘__main__‘: for i in range(20): t=Thread(target=task) t.start()
定时器
from threading import Timer
1 def hello(id): 2 print("hello, world",id) 3 4 5 t = Timer(1, hello,args=(30,)) 6 t.start() # after 1 seconds, "hello, world" will be printed
标签:reading read task rand target int map 执行 and
原文地址:http://www.cnblogs.com/surehunter/p/7896591.html