上一页 1 2 3 4 5 6 7 ··· 10 下一页
摘要: from threading import Thread #线程 import time def task(name): print('%s is running' %name) time.sleep(2) if __name__ == '__main__': t1=Thread(target=ta 阅读全文
posted @ 2019-07-21 08:21 zhouhao666 阅读(117) 评论(0) 推荐(0) 编辑
摘要: from threading import Thread,Lock import time mutex=Lock() n=100 def task(): global n temp=n time.sleep(0.1) n=temp-1 if __name__ == '__main__': l=[] 阅读全文
posted @ 2019-07-20 03:27 zhouhao666 阅读(150) 评论(0) 推荐(0) 编辑
摘要: 死锁:此时执行程序中两个或多个线程发生永久堵塞(等待),每个线程都在等待被其他线程占用并堵塞了的资源。 递归锁:可以多次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) 编辑
摘要: 使用:from concurrent.futures import ProcessPoolExecutor from concurrent.futures import ProcessPoolExecutor import time,random,os def task(name): print(' 阅读全文
posted @ 2019-07-18 14:45 zhouhao666 阅读(167) 评论(0) 推荐(0) 编辑
摘要: from concurrent.futures import ThreadPoolExecutor,ProcessPoolExecutor import time,random,os def task(name,n): print('%s%s is running' %(name,os.getpid 阅读全文
posted @ 2019-07-08 22:31 zhouhao666 阅读(1315) 评论(0) 推荐(0) 编辑
摘要: import time def func1(): for i in range(10000000): i+1 def func2(): for i in range(10000000): i+1 start = time.time() func1() func2() stop = time.time 阅读全文
posted @ 2019-07-07 17:33 zhouhao666 阅读(126) 评论(0) 推荐(0) 编辑
摘要: from gevent import monkey;monkey.patch_all() from socket import * from gevent import spawn #导入spawn之前一定要传入monkey #俩个io密集型任务 def comun(conn): while Tru 阅读全文
posted @ 2019-07-05 16:53 zhouhao666 阅读(190) 评论(0) 推荐(0) 编辑
上一页 1 2 3 4 5 6 7 ··· 10 下一页