1
0
mirror of https://github.com/binary-kitchen/doorlockd synced 2024-12-22 10:24:26 +01:00

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

View File

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