python 多线程信号量semaphore
作者:
lxc198 | 来源:发表于
2018-12-13 16:20 被阅读0次import threading
import logging
import time
def worker(s):
logging.debug('starting')
with s:
name = threading.current_thread().name
print(name)
time.sleep(2)
logging.basicConfig(
level=logging.DEBUG,
format='%(asctime)s (%(threadName)-2s) %(message)s',
)
s = threading.Semaphore(5)
for i in range(100):
t = threading.Thread(
target=worker,
name=str(i),
args=(s,),
)
t.start()
本文标题:python 多线程信号量semaphore
本文链接:https://www.haomeiwen.com/subject/sadbhqtx.html
网友评论