From 0403ebff5cc7660cce2e05421af3d190856a35f8 Mon Sep 17 00:00:00 2001 From: Jakob Ketterl Date: Wed, 15 Sep 2021 15:03:11 +0200 Subject: [PATCH] improve handling of source processes --- owrx/__main__.py | 1 + owrx/sdr.py | 5 +++++ owrx/source/__init__.py | 8 ++++++++ 3 files changed, 14 insertions(+) diff --git a/owrx/__main__.py b/owrx/__main__.py index bac982f..499c3b1 100644 --- a/owrx/__main__.py +++ b/owrx/__main__.py @@ -111,5 +111,6 @@ Support and info: https://groups.io/g/openwebrx WebSocketConnection.closeAll() Services.stop() + SdrService.stopAllSources() ReportingEngine.stopAll() DecoderQueue.stopAll() diff --git a/owrx/sdr.py b/owrx/sdr.py index 503fe5c..da51e9b 100644 --- a/owrx/sdr.py +++ b/owrx/sdr.py @@ -259,3 +259,8 @@ class SdrService(object): if SdrService.availableProfiles is None: SdrService.availableProfiles = AvailableProfiles(SdrService.getActiveSources()) return SdrService.availableProfiles + + @staticmethod + def stopAllSources(): + for source in SdrService.getAllSources().values(): + source.stop() diff --git a/owrx/source/__init__.py b/owrx/source/__init__.py index a932d38..28de49a 100644 --- a/owrx/source/__init__.py +++ b/owrx/source/__init__.py @@ -322,6 +322,7 @@ class SdrSource(ABC): if self.monitor is None: break testsock = socket.socket() + testsock.settimeout(1) try: testsock.connect(("127.0.0.1", self.getPort())) testsock.close() @@ -365,6 +366,13 @@ class SdrSource(ABC): self.setState(SdrSourceState.STOPPING) try: os.killpg(os.getpgid(self.process.pid), signal.SIGTERM) + if self.monitor: + # wait 10 seconds for a regular shutdown + self.monitor.join(10) + # if the monitor is still running, the process still hasn't ended, so kill it + if self.monitor: + logger.warning("source has not shut down normally within 10 seconds, sending SIGKILL") + os.killpg(os.getpgid(self.process.pid), signal.SIGKILL) except ProcessLookupError: # been killed by something else, ignore pass