@@ -36,6 +36,7 @@ from python_hackrf import pyhackrf
3636from libcpp.atomic cimport atomic
3737cimport numpy as cnp
3838import numpy as np
39+ import threading
3940import datetime
4041cimport cython
4142import signal
@@ -148,6 +149,7 @@ cpdef int sweep_callback(c_pyhackrf.PyHackrfDevice device, cnp.ndarray[cnp.int8_
148149 device_data[' sweep_started' ] = True
149150
150151 if not working_sdrs[device_id].load():
152+ device_data[' notify_finished' ].set()
151153 return - 1
152154
153155 if not device_data[' sweep_started' ]:
@@ -352,6 +354,7 @@ def pyhackrf_sweep(frequencies: list[int] | None = None, sample_rate: int = 20_0
352354 ' start_frequency' : int (frequencies[0 ] * 1e6 ),
353355 ' fft_size' : fft_size,
354356 ' window' : np.hanning(fft_size),
357+ ' notify_finished' : threading.Event(),
355358
356359 ' binary_output' : binary_output,
357360 ' one_shot' : one_shot,
@@ -405,7 +408,8 @@ def pyhackrf_sweep(frequencies: list[int] | None = None, sample_rate: int = 20_0
405408 sys.stderr.write(f' Total sweeps: {device_data["sweep_count"]} in {time_now - time_start:.5f} seconds ({sweep_rate :.2f} sweeps/second)\n ' )
406409
407410 working_sdrs[device_id].store(0 )
408- device_serial = device.serialno
411+ device_data[' notify_finished' ].wait()
412+ sdr_ids.pop(device.serialno, None )
409413
410414 if antenna_enable:
411415 try :
@@ -420,8 +424,6 @@ def pyhackrf_sweep(frequencies: list[int] | None = None, sample_rate: int = 20_0
420424 except Exception as e:
421425 sys.stderr.write(f' {e}\n ' )
422426
423- sdr_ids.pop(device_serial, None )
424-
425427 try :
426428 pyhackrf.pyhackrf_exit()
427429 if print_to_console:
0 commit comments