一.进程 我们电脑的应用程序,都是进程,进程是资源分配的单位.进程切换需要的资源最大,效率低. 进程之间相互独立 cpu密集的时候适合用多进程 #多进程并发 import multiprocessing from multiprocessing import Pool import time def test1(): for i in range(10): time.sleep(1) print('test', i) def test2():…
from multiprocessing import Pool,Manager import time def hanshu(queue,a): n = 1 while n<50: # print('\r正在工作%d'%a,end='') n+=1 # [步骤3]往队列中发送一条消息 queue.put(a) time.sleep(2) def main(): print('执行main函数') for i in range(0,10): po.apply_async(hanshu,args=…
from multiprocessing import Process import json import time from multiprocessing import Lock def show(i): with open('ticket') as f: dic = json.load(f)#load直接打开文件, 不用read, loads操作字符串,需要read print('余票: %s' % dic['ticket']) def buy_ticket(i,lock): lock.…
Interprocess Communication Android offers a mechanism for interprocess communication (IPC) using remote procedure calls (RPCs), in which a method is called by an activity or other application component, but executed remotely (in another process), wit…
一 进程创建的两种方式 from multiprocessing import Process import time def task(name): print(f'{name} is running') time.sleep(2) print(f'{name} is gone') if __name__ == '__main__': #在windows环境下, 开启进程必须在 __name__ == '__main__' 下面 p = Process(target=task,args=('常…