摘要: main process linemodule name: __main__parent process: 2728process id: 25524 called from child process function fmodule name: __mp_main__parent process 阅读全文
posted @ 2018-11-18 21:29 rongye 阅读(227) 评论(0) 推荐(0) 编辑
摘要: from multiprocessing import Process import time def f(name): time.sleep(2) print('hello', name) if __name__ == '__main__': p = Process(target=f, args= 阅读全文
posted @ 2018-11-18 21:19 rongye 阅读(145) 评论(0) 推荐(0) 编辑
摘要: import threading,timeimport queueq = queue.Queue(maxsize=10)def Producer(name): count = 1 while True: q.put("骨头%s" % count) print("生产了骨头",count) count 阅读全文
posted @ 2018-11-18 17:14 rongye 阅读(131) 评论(0) 推荐(0) 编辑
摘要: queue is especially useful in threaded programming when information must be exchanged safely between multiple threads. 阅读全文
posted @ 2018-11-18 16:51 rongye 阅读(162) 评论(0) 推荐(0) 编辑
摘要: import timeimport threadingevent = threading.Event()def lighter(): count = 0 event.set() #先设置绿灯 while True: if count >5 and count < 10: #改成红灯 event.cl 阅读全文
posted @ 2018-11-18 16:15 rongye 阅读(168) 评论(0) 推荐(0) 编辑
摘要: import threading, timedef run(n): semaphore.acquire() time.sleep(1) print("run the thread: %s\n" % n) semaphore.release()if __name__ == '__main__': se 阅读全文
posted @ 2018-11-18 15:04 rongye 阅读(189) 评论(0) 推荐(0) 编辑
摘要: import threading, timedef run1(): print("grab the first part data") lock.acquire() global num num += 1 lock.release() return numdef run2(): print("gra 阅读全文
posted @ 2018-11-18 14:59 rongye 阅读(186) 评论(0) 推荐(0) 编辑
摘要: import threadingimport timedef run(n): lock.acquire() global num num +=1 lock.release() time.sleep(1)lock = threading.Lock()num = 0t_objs = [] #存线程实例f 阅读全文
posted @ 2018-11-18 14:19 rongye 阅读(129) 评论(0) 推荐(0) 编辑
摘要: 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 阅读全文
posted @ 2018-11-18 11:10 rongye 阅读(238) 评论(0) 推荐(0) 编辑