【发布时间】:2015-07-13 23:20:38
【问题描述】:
我在我的代码中使用 threading.semaphore,我想知道是否有办法可以使用这样的代码
if(sema.acquire()!=True):
#do Somthing
我想在循环中使用这段代码,所以我需要获取信号量是被占用还是被释放 或者在我的代码中使用这样的代码
if(sema.get_value!=1):
#do something
我阅读了这个文档,但我找不到我的答案 https://docs.python.org/3/library/threading.html
【问题讨论】:
-
不要将布尔值与
!=进行比较;请改用if not sema.acquire()。
标签: python multithreading semaphore