摘要: 死锁:此时执行程序中两个或多个线程发生永久堵塞(等待),每个线程都在等待被其他线程占用并堵塞了的资源。 递归锁:可以多次acquire加锁 使用:from threading import RLock mutexA=RLock() from threading import Thread,Lock 阅读全文
posted @ 2019-07-19 11:18 zhouhao666 阅读(207) 评论(0) 推荐(0) 编辑
摘要: from threading import Thread,Semaphore import time,random sm=Semaphore(5) def task(name): sm.acquire() #或者with sm print('%s 正在上厕所' %name) time.sleep(r 阅读全文
posted @ 2019-07-19 08:04 zhouhao666 阅读(143) 评论(0) 推荐(0) 编辑
摘要: from threading import Thread,Event import time event=Event() #制造一个event事件 def light(): print('红灯正亮着') time.sleep(3) event.set() #绿灯亮 def car(name): pr 阅读全文
posted @ 2019-07-19 07:55 zhouhao666 阅读(129) 评论(0) 推荐(0) 编辑
摘要: import queue q=queue.Queue(3) #先进先出 q.put(1) q.put(2) q.put(3) print(q.get()) print(q.get()) print(q.get()) 结果: 1 2 3 import queue q=queue.LifoQueue(3 阅读全文
posted @ 2019-07-19 07:44 zhouhao666 阅读(85) 评论(0) 推荐(0) 编辑