add lockfie support

This commit is contained in:
Andrew de Quincey 2021-10-30 15:32:44 +01:00
parent ded995d671
commit 9699834979

View File

@ -1,6 +1,8 @@
import threading
import time
import random
import os
import fcntl
import datetime
import logging
import json
@ -378,6 +380,13 @@ class SimulatedOven(Oven):
class RealOven(Oven):
def __init__(self):
self.lockfd = os.open('/tmp/kiln.lock', os.O_TRUNC | os.O_CREAT | os.O_RDWR)
try:
fcntl.flock(self.lockfd, fcntl.LOCK_EX | fcntl.LOCK_NB)
except OSError:
print("Unable to start as another process is using the oven")
exit(1)
self.board = Board()
self.output = Output()
self.reset()