7.15python进程锁
Posted 吾皇万岁
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了7.15python进程锁相关的知识,希望对你有一定的参考价值。
#!/usr/bin/env python #!--*--coding:utf-8 --*-- #[email protected] :2018/7/14 17:33 #[email protected] 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(‘