pydoorlock: Doorlock: use run instead of Popen

Popen created an object that we need to wait for, run won't. Use a
pseudo-shell, and spawn the process in the background.

Signed-off-by: Ralf Ramsauer <ralf@binary-kitchen.de>
This commit is contained in:
Ralf Ramsauer 2019-06-14 00:25:53 +02:00
parent 0511fac330
commit e69c314f97
1 changed files with 8 additions and 4 deletions

View File

@ -1,7 +1,7 @@
"""
Doorlockd -- Binary Kitchen's smart door opener
Copyright (c) Binary Kitchen e.V., 2018
Copyright (c) Binary Kitchen e.V., 2018-2019
Author:
Ralf Ramsauer <ralf@binary-kitchen.de>
@ -19,7 +19,7 @@ import logging
from enum import Enum
from random import sample
from subprocess import Popen
from subprocess import run
from serial import Serial
from threading import Thread
from time import sleep
@ -56,6 +56,10 @@ def choose_insult():
return sample(eperm_insults, 1)[0]
def run_background(cmd):
run('%s &' % cmd, shell=True)
class DoorlockResponse(Enum):
Success = 0
Perm = 1
@ -241,14 +245,14 @@ class DoorHandler:
elif new_state == DoorState.Closed:
filename = self.wave_lock
Popen(['nohup', 'aplay', join(self.sounds_prefix, filename)])
run_background('aplay %s' % join(self.sounds_prefix, filename))
def run_hook(self, script):
if not self.run_hooks:
log.info('Hooks disabled: not starting %s' % script)
return
log.info('Starting hook %s' % script)
Popen(['nohup', join(self.scripts_prefix, script)])
run_background(join(self.scripts_prefix, script))
def register_callback(self, callback):
self._callback = callback