摘要:
queue is especially useful in threaded programming when information must be exchanged safely between multiple threads. 阅读全文
摘要:
import timeimport threadingevent = threading.Event()def lighter(): count = 0 event.set() #先设置绿灯 while True: if count >5 and count < 10: #改成红灯 event.cl 阅读全文
摘要:
import threading, timedef run(n): semaphore.acquire() time.sleep(1) print("run the thread: %s\n" % n) semaphore.release()if __name__ == '__main__': se 阅读全文
摘要:
import threading, timedef run1(): print("grab the first part data") lock.acquire() global num num += 1 lock.release() return numdef run2(): print("gra 阅读全文
摘要:
import threadingimport timedef run(n): lock.acquire() global num num +=1 lock.release() time.sleep(1)lock = threading.Lock()num = 0t_objs = [] #存线程实例f 阅读全文
摘要:
import threadingimport timedef run(n): print("task ",n ) time.sleep(2) print("task done",n)start_time = time.time()t_objs = [] #存线程实例for i in range(50 阅读全文