摘要: 非阻塞 阅读全文
posted @ 2018-09-12 10:38 Woowo 阅读(109) 评论(0) 推荐(0) 编辑
摘要: def consumer(): while True: x = yield print('处理了数据:',x) def producer(): c = consumer() next(c) for i in range(10): print('生产了数据:',i) c.send(i) produce... 阅读全文
posted @ 2018-09-11 16:01 Woowo 阅读(94) 评论(0) 推荐(0) 编辑
摘要: import time from concurrent.futures import ThreadPoolExecutor def func(n): time.sleep(2) print(n) return n*n tpool = ThreadPoolExecutor(max_workers=5) t_lst = [] for i in range(20): ... 阅读全文
posted @ 2018-09-11 09:37 Woowo 阅读(95) 评论(0) 推荐(0) 编辑
摘要: from threading import Thread,Semaphore import time def func(sem,a,b): sem.acquire() time.sleep(0.5) print(a+b) sem.release() sem = Semaphore(4) t_lst = [] for i in range(10): t ... 阅读全文
posted @ 2018-09-10 18:57 Woowo 阅读(129) 评论(0) 推荐(0) 编辑
摘要: from threading import Lock,Thread import time def func(): global n temp = n time.sleep(0.2) n = temp -1 n = 10 t_lst = [] for i in range(10): t = Thread(target=func) t.start(... 阅读全文
posted @ 2018-09-10 11:03 Woowo 阅读(119) 评论(0) 推荐(0) 编辑
摘要: import time from threading import Thread def func1(): while True: print('*'*10) time.sleep(1) def func2(): print('in func2') time.sleep(5) t = Thread(target=func1,) t.d... 阅读全文
posted @ 2018-09-10 09:20 Woowo 阅读(82) 评论(0) 推荐(0) 编辑
摘要: import time from threading import Thread def func(n): time.sleep(1) print(n) for i in range(10): t = Thread(target=func,args=(i,)) t.start() from threading import Thread import tim... 阅读全文
posted @ 2018-09-09 20:01 Woowo 阅读(93) 评论(0) 推荐(0) 编辑
摘要: from multiprocessing import Pool,Process import time def func(n): for i in range(10): print(n+1) if __name__ == '__main__': st1 = time.time() pool = Pool(5) pool.map(func,ra... 阅读全文
posted @ 2018-09-09 10:10 Woowo 阅读(120) 评论(0) 推荐(0) 编辑
摘要: from multiprocessing import Pipe,Process def func(conn1): while True: msg = conn1.recv() if msg is None: break print(msg) if __name__ == '__main__': conn1,conn2 = Pi... 阅读全文
posted @ 2018-09-08 22:26 Woowo 阅读(133) 评论(0) 推荐(0) 编辑
摘要: from multiprocessing import Manager,Process def main(dic): dic['count'] -= 1 print(dic) if __name__ == '__main__': m = Manager() dic = m.dict({'count':100}) p_dict = [] p = ... 阅读全文
posted @ 2018-09-08 20:56 Woowo 阅读(317) 评论(0) 推荐(0) 编辑