摘要:
非阻塞 阅读全文
摘要:
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... 阅读全文
摘要:
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): ... 阅读全文
摘要:
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 ... 阅读全文
摘要:
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(... 阅读全文
摘要:
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... 阅读全文
摘要:
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... 阅读全文
摘要:
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... 阅读全文
摘要:
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... 阅读全文
摘要:
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 = ... 阅读全文