Prevented muliprocessing

This commit is contained in:
Pünkösd Marcell 2021-12-12 19:15:11 +01:00
parent 0ea6b8c69b
commit 4e7f3b79a6
1 changed files with 24 additions and 19 deletions

View File

@ -9,6 +9,8 @@ import os
from utils import BirbnetesIoTPlatformStatusDriver
from threading import Lock
"""
Abstract base class for signalprocessor
"""
@ -24,6 +26,8 @@ class SoundSignalProcessor(AbcSignalProcessor):
SoundSignalProcessor class, responsible for handling the sound signal processor pipeline.
"""
super_multi_signal_processing_preventor_to_make_queue_great_again = Lock()
def __init__(self):
"""
Create dependency objects.
@ -37,28 +41,29 @@ class SoundSignalProcessor(AbcSignalProcessor):
Process a sound sample.
:return:
"""
soundsample_name = self.soundsensor.getvalue()
with SoundSignalProcessor.super_multi_signal_processing_preventor_to_make_queue_great_again:
soundsample_name = self.soundsensor.getvalue()
if not soundsample_name: # No new sample... nothing to do
return
if not soundsample_name: # No new sample... nothing to do
return
try:
sample_decision = self.soundpreprocessor.preprocesssignal(soundsample_name)
except Exception as e:
logging.exception(e)
BirbnetesIoTPlatformStatusDriver.enqueue_pattern('red', [1, 1, 1])
os.unlink(soundsample_name)
return
try:
sample_decision = self.soundpreprocessor.preprocesssignal(soundsample_name)
except Exception as e:
logging.exception(e)
BirbnetesIoTPlatformStatusDriver.enqueue_pattern('red', [1, 1, 1])
os.unlink(soundsample_name)
return
if sample_decision:
BirbnetesIoTPlatformStatusDriver.enqueue_pattern('green', [1, 0, 1])
if sample_decision:
BirbnetesIoTPlatformStatusDriver.enqueue_pattern('green', [1, 0, 1])
try:
self.soundsender.sendvalue(soundsample_name, sample_decision)
except (ConnectionError, requests.HTTPError) as e:
logging.exception(e)
BirbnetesIoTPlatformStatusDriver.enqueue_pattern('red', [1, 0, 1, 0, 1])
os.unlink(soundsample_name)
return
try:
self.soundsender.sendvalue(soundsample_name, sample_decision)
except (ConnectionError, requests.HTTPError) as e:
logging.exception(e)
BirbnetesIoTPlatformStatusDriver.enqueue_pattern('red', [1, 0, 1, 0, 1])
os.unlink(soundsample_name)
return
os.unlink(soundsample_name)