摘要:
1 #!/usr/bin/env python 2 import multiprocessing 3 import time 4 def f1(a1): 5 time.sleep(2) 6 print(a1) 7 if __name__ == '__main__': 8 t = multiprocessing.Process(target=f1,args=... 阅读全文
摘要:
1 #!/usr/bin/env python 2 from multiprocessing import Process 3 4 li = [] 5 def f1(a1): 6 li.append(a1) 7 print(li) 8 if __name__ == '__main__': 9 for i in range(10): 10 ... 阅读全文
摘要:
1 #!/usr/bin/env python 2 from multiprocessing import Process,Manager 3 4 #Manager进程与进程之间通信 5 def Foo(i,dic): 6 dic[i] = 100+i 7 print(dic.values()) 8 if __name__ == '__main__': 9 ... 阅读全文
摘要:
1 import queue 2 import threading 3 4 5 class ThreadPool(object): 6 7 def __init__(self, max_num=20): 8 self.queue = queue.Queue(max_num) 9 for i in range(max_num): 10... 阅读全文
摘要:
1 import queue 2 import contextlib 3 import time 4 @contextlib.contextmanager 5 def worker_state(xxx,val): 6 xxx.append(val) 7 print("before",xxx) 8 try: 9 time.sleep(1) ... 阅读全文
摘要:
1 import queue 2 import threading 3 import contextlib 4 import time 5 6 StopEvent = object() 7 8 9 class ThreadPool(object): 10 11 def __init__(self, max_num): 12 13 ... 阅读全文