Skip to content

Commit 9ee0887

Browse files
committed
updated
1 parent 7257849 commit 9ee0887

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

python_hackrf/pyhackrf_tools/pyhackrf_sweep.pyx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ from python_hackrf import pyhackrf
3636
from libcpp.atomic cimport atomic
3737
cimport numpy as cnp
3838
import numpy as np
39+
import threading
3940
import datetime
4041
cimport cython
4142
import 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

Comments
 (0)