摘要:
1 import threading 2 import time 3 def f0(): 4 pass 5 def f1(a1,a2): 6 time.sleep(10) 7 f0() 8 print("1") 9 10 t1 = threading.Thread(target=f1,args=(111,123)) 11 # t.setDaem... 阅读全文
摘要:
1 from multiprocessing import Process,Pool 2 import time 3 #进程池的使用 4 def Foo(i): 5 time.sleep(2) 6 return i+100 7 def Bar(arg): 8 print (arg) 9 10 #print pool.apply(Foo,(1,)) 11... 阅读全文
摘要:
1 import threading 2 import time 3 globals_num = 0 4 lock = threading.RLock() 5 def func(): 6 lock.acquire()#获得锁 7 global globals_num 8 globals_num += 1 9 time.sleep(1) 10 ... 阅读全文
摘要:
1 #!/usr/bin/env python 2 import threading 3 # event.wait()##阻断线程向下执行 event_obj.set()#释放进程向下执行 4 def do(event): 5 print('start') 6 event.wait()##阻断线程向下执行 7 print('execute') 8 9 ... 阅读全文
摘要:
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 ... 阅读全文