Skip to content

Commit 1ed92e0

Browse files
committed
couple more small fixes
1 parent 55067ba commit 1ed92e0

File tree

3 files changed

+23
-17
lines changed

3 files changed

+23
-17
lines changed

auto_rx/auto_rx.py

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1073,27 +1073,28 @@ def main():
10731073
if args.type != None:
10741074
handle_scan_results()
10751075

1076-
# Loop - Optimized to use event-driven queue instead of pure polling
1076+
# Loop - Event-driven processing with periodic maintenance
10771077
while True:
1078-
# OPTIMIZATION: Use blocking queue get with timeout instead of sleep
1079-
# This allows immediate response to scan results while still doing periodic cleanup
1078+
# Process any scan results in the queue
1079+
# handle_scan_results() checks qsize and processes all available results
1080+
handle_scan_results()
1081+
1082+
# Check for finished tasks
1083+
clean_task_list()
1084+
1085+
# Wait for new scan results or timeout after 2 seconds
1086+
# This allows immediate response when results arrive while still doing periodic cleanup
10801087
try:
1081-
# Wait for scan result with timeout (replaces pure 2s sleep)
1082-
# If result arrives, it will be processed by handle_scan_results() below
1088+
# Block until result arrives or timeout
10831089
result = autorx.scan_results.get(timeout=2.0)
1084-
# Put it back so handle_scan_results() can process it with all safety checks
1090+
# Put it back for handle_scan_results() to process on next loop iteration
1091+
# This maintains the existing queue processing logic without changes
10851092
autorx.scan_results.put(result)
10861093
except Empty:
1087-
# Queue.get timeout - this is normal, means no scan results for 2s
1088-
# Continue to cleanup tasks
1094+
# Timeout - normal condition when no scan results for 2s
1095+
# Loop will continue to next iteration for periodic maintenance
10891096
pass
10901097

1091-
# Check for finished tasks (runs every 2s when queue is empty, or after processing result)
1092-
clean_task_list()
1093-
1094-
# Handle scan results with all safety checks (temporary blocks, spacing, allocation, etc.)
1095-
handle_scan_results()
1096-
10971098
if len(autorx.sdr_list) == 0:
10981099
# No Functioning SDRs!
10991100
logging.critical("Task Manager - No SDRs available! Cannot continue...")

auto_rx/autorx/scan.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1169,7 +1169,9 @@ def sonde_search(self, first_only=False):
11691169
return _search_results
11701170

11711171
except Exception as e:
1172+
import traceback
11721173
self.log_error(f"Async scanning failed: {e}, falling back to sequential")
1174+
self.log_debug(f"Async scan traceback: {traceback.format_exc()}")
11731175

11741176
# Standard sequential scanning (for RTLSDR, SpyServer, or single peaks)
11751177
else:

auto_rx/autorx/scan_async.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ async def detect_sonde_async(
173173
)
174174

175175
process = None
176+
ret_output = ""
176177
try:
177178
_start = time.time()
178179

@@ -403,12 +404,14 @@ def run_async_scan(peak_frequencies: list, max_concurrent: int = 2, **detect_kwa
403404
asyncio.get_running_loop()
404405
# An event loop is running - we can't use asyncio.run() here
405406
# Solution: Run the async code in a separate thread with its own event loop
407+
# Note: We create the coroutine inside the worker thread to avoid cross-thread issues
406408
import concurrent.futures
407-
with concurrent.futures.ThreadPoolExecutor() as executor:
408-
future = executor.submit(
409-
asyncio.run,
409+
def run_in_thread():
410+
return asyncio.run(
410411
scan_peaks_concurrent(peak_frequencies, max_concurrent, **detect_kwargs)
411412
)
413+
with concurrent.futures.ThreadPoolExecutor() as executor:
414+
future = executor.submit(run_in_thread)
412415
return future.result()
413416
except RuntimeError:
414417
# No event loop running - we can use asyncio.run() directly

0 commit comments

Comments
 (0)