摘要:
main process linemodule name: __main__parent process: 2728process id: 25524 called from child process function fmodule name: __mp_main__parent process 阅读全文
摘要:
from multiprocessing import Process import time def f(name): time.sleep(2) print('hello', name) if __name__ == '__main__': p = Process(target=f, args= 阅读全文
摘要:
import threading,timeimport queueq = queue.Queue(maxsize=10)def Producer(name): count = 1 while True: q.put("骨头%s" % count) print("生产了骨头",count) count 阅读全文
摘要:
queue is especially useful in threaded programming when information must be exchanged safely between multiple threads. 阅读全文
摘要:
import timeimport threadingevent = threading.Event()def lighter(): count = 0 event.set() #先设置绿灯 while True: if count >5 and count < 10: #改成红灯 event.cl 阅读全文
摘要:
import threading, timedef run(n): semaphore.acquire() time.sleep(1) print("run the thread: %s\n" % n) semaphore.release()if __name__ == '__main__': se 阅读全文
摘要:
import threading, timedef run1(): print("grab the first part data") lock.acquire() global num num += 1 lock.release() return numdef run2(): print("gra 阅读全文
摘要:
import threadingimport timedef run(n): lock.acquire() global num num +=1 lock.release() time.sleep(1)lock = threading.Lock()num = 0t_objs = [] #存线程实例f 阅读全文
摘要:
import threadingimport timedef run(n): print("task ",n ) time.sleep(2) print("task done",n)start_time = time.time()t_objs = [] #存线程实例for i in range(50 阅读全文