From 4e7f3b79a62f0bb1336e292ae34311d1a302ad82 Mon Sep 17 00:00:00 2001 From: marcsello Date: Sun, 12 Dec 2021 19:15:11 +0100 Subject: [PATCH] Prevented muliprocessing --- src/signal_processor/soundsignalprocessor.py | 43 +++++++++++--------- 1 file changed, 24 insertions(+), 19 deletions(-) diff --git a/src/signal_processor/soundsignalprocessor.py b/src/signal_processor/soundsignalprocessor.py index 55fdca4..3890a96 100644 --- a/src/signal_processor/soundsignalprocessor.py +++ b/src/signal_processor/soundsignalprocessor.py @@ -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)