improve handling of source processes

This commit is contained in:
Jakob Ketterl 2021-09-15 15:03:11 +02:00
parent 6129b92277
commit 0403ebff5c
3 changed files with 14 additions and 0 deletions

View File

@ -111,5 +111,6 @@ Support and info: https://groups.io/g/openwebrx
WebSocketConnection.closeAll()
Services.stop()
SdrService.stopAllSources()
ReportingEngine.stopAll()
DecoderQueue.stopAll()

View File

@ -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()

View File

@ -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