摘要:
#练习:未使用共享变量 from multiprocessing import Process def f(n, a): n = 3.1415927 for i in range(len(a)): a[i] = -a[i] if __name__ == '__main__': num = 0 arr = range(10) p =... 阅读全文
摘要:
#练习:用event事件控制进程执行顺序,下面例子中,主进程main函数在创建了子进程之后,依然会往下执行,所以会出现主进程先打印出来的情况 import multiprocessing import time def wait_for_event(e): #Wait for the event to be set before doing anything print 'wa... 阅读全文
摘要:
#练习:测试单进程和多进程执行效率 import multiprocessing import time def m1(x): time.sleep(0.01) return x * x if __name__ == '__main__': #并行并发 pool = multiprocessing.Pool(multiprocessing.cpu_count(... 阅读全文