hackrf_sweep: fix race condition when stopping

When stopping, the process may die right before we try to read from its stdout,
generating the following error:

Traceback (most recent call last):
  File "/usr/lib/python3.6/site-packages/qspectrumanalyzer/backends/hackrf_sweep.py", line 146, in run
    buf = self.process.stdout.read(4)
AttributeError: 'NoneType' object has no attribute 'stdout'

Catch the error instead of crashing.
This commit is contained in:
Michael Lass 2017-03-24 21:52:53 +01:00
parent bc3319ba82
commit 5985cb4bfe

View File

@ -1,4 +1,4 @@
import subprocess, pprint, struct, shlex, time
import subprocess, pprint, struct, shlex, sys, time
import numpy as np
from Qt import QtCore
@ -143,10 +143,20 @@ class PowerThread(BasePowerThread):
self.powerThreadStarted.emit()
while self.alive:
buf = self.process.stdout.read(4)
try:
buf = self.process.stdout.read(4)
except AttributeError as e:
print(e, file=sys.stderr)
continue
if buf:
(record_length,) = struct.unpack('I', buf)
buf = self.process.stdout.read(record_length)
try:
buf = self.process.stdout.read(record_length)
except AttributeError as e:
print(e, file=sys.stderr)
continue
if buf:
self.parse_output(buf)
else: