Skip to content

Commit

Permalink
better thread exit
Browse files Browse the repository at this point in the history
  • Loading branch information
rpatel3001 committed Mar 1, 2024
1 parent 3d6c17e commit bef7249
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions rootfs/scripts/soapy2tcp.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,13 @@ def rx_thread(sdrcfg, rxStream, rxcfg, tx_init, inbufs, rxq):
sdr.deactivateStream(rxStream)
sdr.closeStream(rxStream)
if environ.get("EXIT_ON_ERROR"):
print("[rx] Quitting script...")
raise OverflowError
print("[rx] Quitting script...")
for i in range(len(rxq)):
rxq[i].put_nowait((-1, -1))
raise StopIteration
else:
print("[rx] Quitting thread...")
return
print("[rx] Restarting thread...")
return
elif samps < realmtu:
print(f"[rx] Got only {samps} samples, expected {realmtu}")

Expand Down Expand Up @@ -142,6 +144,9 @@ def tx_thread(rxcfg, chancfg, tx_init, inbufs, rxq):

while True:
bufidx, insamps = rxq.get() # receive a buffer index and length
if bufidx < 0:
print(f"[tx {chancfg['idx']}] Got negative bufidx, quitting thread")
raise StopIteration
decsamps = insamps // chancfg['deci']
outsamps = decsamps * 2
# copy out the received samples
Expand Down Expand Up @@ -169,7 +174,7 @@ def thread_wrapper(func, *args):
try:
print(f"[{func.__name__}] starting thread")
func(*args)
except OverflowError:
except StopIteration:
print(traceback.format_exc())
print(f"[{func.__name__}] exception; quitting script")
return
Expand Down

0 comments on commit bef7249

Please sign in to comment.