抢票小程序
抢票小程序 我们可以利用所学的内容来写一个简易的抢票小程序 from multiprocessing import Process import json,time,os def search(): time.sleep(1) # 模拟网络io with open('db.txt',mode='rt',encoding='utf-8') as f: res = json.load(f) print(f'还剩{res["count"]}') def get(): with open('db.txt',mode='rt',encoding='utf-8') as f: res = json.load(f) # print(f'还剩{res["count"]}') time.sleep(1) # 模拟网络io if res['count'] > 0: res['count'] -= 1 with open('db.txt',mode='wt',encoding='utf-8') as f: json.dump(res,f) time.sleep(1.5) # 模拟网络io print(f'进程{os.getpid()} 抢票成功') else: print('票已经售空啦!!!!!!!!!!!') def task(): search() get() if __name__ == '_