Commit 9b9df9e
fix(ble): resolve BLE hangs on macOS without --debug flag
This fixes two issues that caused BLE connections to hang on macOS
when not using the --debug flag:
1. Race condition in BLEClient event loop initialization
- The event loop thread was started but asyncio operations were
submitted before the loop was actually running
- Added threading.Event synchronization to ensure the event loop
is running before any operations are submitted
- The ready signal is sent from within the loop via call_soon()
to guarantee the loop is truly active
2. CoreBluetooth callback delivery on macOS
- On macOS, CoreBluetooth requires occasional I/O operations for
callbacks to be properly delivered to the main thread
- Without --debug, no I/O was happening, causing callbacks to
never be processed and operations to hang indefinitely
- Added sys.stdout.flush() call before waiting for async results
to trigger the necessary I/O
The --debug flag masked these issues because:
- Debug logging introduces timing delays that let the event loop start
- Logger I/O triggers the necessary callback delivery mechanism
Co-Authored-By: Claude <noreply@anthropic.com>
Signed-off-by: Aleksei Sviridkin <f@lex.la>1 parent b26d80f commit 9b9df9e
1 file changed
+20
-2
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| 7 | + | |
7 | 8 | | |
8 | 9 | | |
9 | | - | |
| 10 | + | |
10 | 11 | | |
11 | 12 | | |
12 | 13 | | |
| |||
258 | 259 | | |
259 | 260 | | |
260 | 261 | | |
| 262 | + | |
261 | 263 | | |
262 | 264 | | |
263 | 265 | | |
264 | 266 | | |
265 | 267 | | |
| 268 | + | |
266 | 269 | | |
267 | 270 | | |
268 | 271 | | |
| |||
306 | 309 | | |
307 | 310 | | |
308 | 311 | | |
309 | | - | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
310 | 326 | | |
311 | 327 | | |
312 | 328 | | |
313 | 329 | | |
314 | 330 | | |
315 | 331 | | |
| 332 | + | |
| 333 | + | |
316 | 334 | | |
317 | 335 | | |
318 | 336 | | |
| |||
0 commit comments