正在加载图片...
Python多线程编程 历些毛子代牧大兽 XIDIAN UNIVERSITY ▣threading:信号量 #!/usr/bin/env python3 if name=='main': #-*-coding:utf-8-*- semaphore import threading,time threading.Semaphore(5) class myThread(threading.Thread): threads=[] def run(self): for i in range(100): if semaphore.acquire(): threads.append(myThread()) #注意观察semaphore for t in threads: print(self.name) t.start() time.sleep(5) semaphore.release() 0Python多线程编程 threading:信号量 10 #!/usr/bin/env python3 # -*- coding:utf-8 -*- import threading, time class myThread(threading.Thread): def run(self): if semaphore.acquire(): #注意观察semaphore print(self.name) time.sleep(5) semaphore.release() if __name__==’__main__’: semaphore = threading.Semaphore(5) threads = [] for i in range(100): threads.append(myThread()) for t in threads: t.start()
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有