#!/usr/bin/env python #!--*--coding:utf-8 --*-- #!@Time :2018/7/14 17:33 #!@Author TrueNewBee #锁 # 火车票 import json import time from multiprocessing import Process from multiprocessing import Lock def show(i): with open('ticket') as f: dic = json.load(f) print('余票: %s'%dic['ticket']) def buy_ticket(i,lock): lock.acquire() #拿钥匙进门 with open('ticket') as f: dic = json.load(f) time.sleep(0.1) if dic['ticket'] > 0 : dic['ticket'] -= 1 print('