fix creation of fifo

This commit is contained in:
Alexander Minges 2019-01-31 17:31:38 +01:00
parent e65ed89053
commit a8c7d8e74f

View file

@ -11,7 +11,7 @@ from phytopi import db, models, app
# map commands
camera_cmds = {
'start_timelapse': 'tl 1',
'stop_timelapse': 'tl 0',
'stop_timelapse': 'tl 0'
}
class CameraStatus(Enum):
@ -31,13 +31,18 @@ class CameraWorker(object):
self.status = CameraStatus.STOPPED
def start(self):
# create FIFO
os.mkfifo(self.fifo)
# check if process is already running
if os.path.isfile(self.pidfile):
with open(self.pidfile, 'r') as fh:
self.pid = int(fh.read())
self.status = CameraStatus.IDLE
return
# create FIFO, if not existent
try:
os.mkfifo(self.fifo)
except FileExistsError:
pass
# if not, spawn new process and create pid file
self.proc = subprocess.Popen([self.executable])