diff --git a/lib/oven.py b/lib/oven.py index af2b42f6..0cc3445a 100644 --- a/lib/oven.py +++ b/lib/oven.py @@ -1,6 +1,8 @@ import threading import time import random +import os +import fcntl import datetime import logging import json @@ -378,6 +380,13 @@ def heat_then_cool(self): 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()