From 58c06b00e7906b448a2942f81854ddd979eefa87 Mon Sep 17 00:00:00 2001 From: David Escalona Date: Wed, 28 Sep 2022 14:39:09 +0200 Subject: [PATCH] connectcore-demo-example: fix signal handling for DEY-4.0 With the update to DEY-4.0, the signal handling in the "demoserver.py" Python script stopped working. The call to "event.wait()" caused the application to stop receiving signals. This commit fixes the issue by replacing the event lock mechanism with the "signal.sigwait()" call, which stops the thread execution until any specified signal is received. Signed-off-by: David Escalona --- connectcore-demo-example/demoserver.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/connectcore-demo-example/demoserver.py b/connectcore-demo-example/demoserver.py index 3413466..4ccf40c 100755 --- a/connectcore-demo-example/demoserver.py +++ b/connectcore-demo-example/demoserver.py @@ -31,7 +31,7 @@ import subprocess from logging.handlers import SysLogHandler from subprocess import call, TimeoutExpired -from threading import Thread, Event +from threading import Thread # Constants. @@ -54,7 +54,6 @@ NOT_AVAILABLE = "N/A" # Variables. log = logging.getLogger(APP_NAME) -stop_event = Event() last_cpu_work = 0 last_cpu_total = 0 led_status = {} @@ -1109,8 +1108,6 @@ def signal_handler(signal_number, _frame): _frame: Current stack frame. """ log.debug("Signal received %d", signal_number) - if signal_number in (signal.SIGTERM, signal.SIGINT): - stop_event.set() def main(): @@ -1146,7 +1143,8 @@ def main(): server_thread.deamon = True server_thread.start() - stop_event.wait() + # Wait for termination/interrupt signal. + signal.sigwait([signal.SIGTERM, signal.SIGINT]) server.shutdown() server.server_close()