short circuit the detection process exit code if it already exited

This commit is contained in:
Blake Blackshear 2023-02-03 18:35:23 -06:00
parent 4ffce38fc0
commit 0d8b5aa158

View File

@ -88,6 +88,7 @@ def run_detector(
stop_event = mp.Event() stop_event = mp.Event()
def receiveSignal(signalNumber, frame): def receiveSignal(signalNumber, frame):
logger.info("Signal to exit detection process...")
stop_event.set() stop_event.set()
signal.signal(signal.SIGTERM, receiveSignal) signal.signal(signal.SIGTERM, receiveSignal)
@ -125,6 +126,8 @@ def run_detector(
avg_speed.value = (avg_speed.value * 9 + duration) / 10 avg_speed.value = (avg_speed.value * 9 + duration) / 10
logger.info("Exited detection process...")
class ObjectDetectProcess: class ObjectDetectProcess:
def __init__( def __init__(
@ -144,6 +147,9 @@ class ObjectDetectProcess:
self.start_or_restart() self.start_or_restart()
def stop(self): def stop(self):
# if the process has already exited on its own, just return
if self.detect_process and self.detect_process.exitcode:
return
self.detect_process.terminate() self.detect_process.terminate()
logging.info("Waiting for detection process to exit gracefully...") logging.info("Waiting for detection process to exit gracefully...")
self.detect_process.join(timeout=30) self.detect_process.join(timeout=30)
@ -151,6 +157,7 @@ class ObjectDetectProcess:
logging.info("Detection process didnt exit. Force killing...") logging.info("Detection process didnt exit. Force killing...")
self.detect_process.kill() self.detect_process.kill()
self.detect_process.join() self.detect_process.join()
logging.info("Detection process has exited...")
def start_or_restart(self): def start_or_restart(self):
self.detection_start.value = 0.0 self.detection_start.value = 0.0