互斥锁与join 互斥锁和join都可以把并发变成串行 以下代码是用join实现串行 from multiprocessing import Process import time import json class Foo(object): def search(self, name): with open("db.txt", "r") as f_read: dic = json.load(f_read) time.sleep(1) # 模拟读数据的网络延迟 pr…
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.…