try to catch a failing sdr device
This commit is contained in:
parent
6c2488f052
commit
2d6b0f1877
@ -91,6 +91,10 @@ class SdrService(object):
|
|||||||
return SdrService.sources
|
return SdrService.sources
|
||||||
|
|
||||||
|
|
||||||
|
class SdrSourceException(Exception):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
class SdrSource(object):
|
class SdrSource(object):
|
||||||
def __init__(self, props, port):
|
def __init__(self, props, port):
|
||||||
self.props = props
|
self.props = props
|
||||||
@ -183,6 +187,8 @@ class SdrSource(object):
|
|||||||
self.process = subprocess.Popen(cmd, shell=True, preexec_fn=os.setpgrp)
|
self.process = subprocess.Popen(cmd, shell=True, preexec_fn=os.setpgrp)
|
||||||
logger.info("Started rtl source: " + cmd)
|
logger.info("Started rtl source: " + cmd)
|
||||||
|
|
||||||
|
available = False
|
||||||
|
|
||||||
def wait_for_process_to_end():
|
def wait_for_process_to_end():
|
||||||
rc = self.process.wait()
|
rc = self.process.wait()
|
||||||
logger.debug("shut down with RC={0}".format(rc))
|
logger.debug("shut down with RC={0}".format(rc))
|
||||||
@ -191,17 +197,25 @@ class SdrSource(object):
|
|||||||
self.monitor = threading.Thread(target=wait_for_process_to_end)
|
self.monitor = threading.Thread(target=wait_for_process_to_end)
|
||||||
self.monitor.start()
|
self.monitor.start()
|
||||||
|
|
||||||
while True:
|
retries = 100
|
||||||
|
while retries > 0:
|
||||||
|
retries -= 1
|
||||||
|
if self.monitor is None:
|
||||||
|
break
|
||||||
testsock = socket.socket()
|
testsock = socket.socket()
|
||||||
try:
|
try:
|
||||||
testsock.connect(("127.0.0.1", self.getPort()))
|
testsock.connect(("127.0.0.1", self.getPort()))
|
||||||
testsock.close()
|
testsock.close()
|
||||||
|
available = True
|
||||||
break
|
break
|
||||||
except:
|
except:
|
||||||
time.sleep(0.1)
|
time.sleep(0.1)
|
||||||
|
|
||||||
self.modificationLock.release()
|
self.modificationLock.release()
|
||||||
|
|
||||||
|
if not available:
|
||||||
|
raise SdrSourceException("rtl source failed to start up")
|
||||||
|
|
||||||
for c in self.clients:
|
for c in self.clients:
|
||||||
c.onSdrAvailable()
|
c.onSdrAvailable()
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user