from multiprocessing import Process,Lock import json,random,time,os def search(): #查票 with open("db.txt",encoding='utf-8') as f: dic=json.load(f) print("%s 剩余票数 %s" %(os.getpid(),dic['count'])) def get(): #抢票 with open("db.txt",encoding='utf-8') as read_f: dic = json.load(read_f) if dic['count'] > 0: dic['count'] -=1 time.sleep(random.randint(1,3)) #模拟手速+网速 with open("db.txt",'w', encoding='utf-8') as write_f: json.dump(dic,write_f) print("