Using BleakClient's unpair() causes crash
See original GitHub issue- bleak version: 0.14.2
- Python version: 3.10.1
- Operating System: Windows 11 Pro, version: 21H2
- BlueZ version (
bluetoothctl -v
) in case of Linux:
Description
My program connects to a device writes/reads some characteristics and then disconnects. After some seconds the procedure repeats. I am getting the following error message after running the application for some minutes, if I am using the BleakClient’s unpair() function before disconnection - actually this function causes disconnection itself. If the the unpair() function is not called just the disconnect() the issue does not pop up.
Exception has occurred: CancelledError
exception: no description
File "C:\Users\andras.kalmar\BLE_assistant\ccis-assistant-pythonble-33867\src\main.py", line 90, in scanner_loop
success = await bleClient.connect(unit_id=key)
File "C:\Users\andras.kalmar\BLE_assistant\ccis-assistant-pythonble-33867\src\main\tssbleclient\tss_ble_client.py", line 634, in connect
await self.ble_client.connect(timeout=self.CONNECT_TIMEOUT)
File "C:\Users\andras.kalmar\AppData\Roaming\Python\Python310\site-packages\bleak\backends\winrt\client.py", line 276, in connect
await self.get_services()
File "C:\Users\andras.kalmar\AppData\Roaming\Python\Python310\site-packages\bleak\backends\winrt\client.py", line 467, in get_services
await self._requester.get_gatt_services_async(
During handling of the above exception, another exception occurred:
File "C:\Program Files\Python_3_1_0\Lib\asyncio\base_events.py", line 641, in run_until_complete
return future.result()
File "C:\Program Files\Python_3_1_0\Lib\asyncio\runners.py", line 44, in run
return loop.run_until_complete(main)
File "C:\Users\andras.kalmar\BLE_assistant\ccis-assistant-pythonble-33867\src\main.py", line 57, in scanner_loop_async
asyncio.run(scanner_loop())
File "C:\Users\andras.kalmar\BLE_assistant\ccis-assistant-pythonble-33867\src\main.py", line 287, in <lambda>
threading.Thread(target=lambda: scanner_loop_async()).start()
File "C:\Program Files\Python_3_1_0\Lib\threading.py", line 946, in run
self._target(*self._args, **self._kwargs)
File "C:\Program Files\Python_3_1_0\Lib\threading.py", line 1009, in _bootstrap_inner
self.run()
File "C:\Program Files\Python_3_1_0\Lib\threading.py", line 966, in _bootstrap
self._bootstrap_inner()
Issue Analytics
- State:
- Created 2 years ago
- Comments:5
Top Results From Across the Web
[Android/Windows] Crash by Inavalid Memory Access ... - GitHub
What happens? BLEACH SoulCarnival &BLEACH SoulCarnival 2 sometime crash at timing of loading. Please see attached screenshot of inavalid memory ...
Read more >AH4 - Week 13 - Lippincott NCLEX Review Ch. 3 Test 17 ...
Three hours ago, a client was thrown From a car into a ditch, and he is now admitted to the emergency department in...
Read more >Unique Boutique Lawsuit - When Beauty Turns Ugly - YouTube
The Hair Bleach That SCALPED Clients - Unique Boutique Lawsuit - When ... bleach horror story 23:43 Can you leave the salon with...
Read more >Colorist Explains What Does Bleach Does To Hair - Refinery29
Everything you need to know before bleaching your hair. ... To help us with this lightweight chemistry crash course, we enlisted Kingsley ...
Read more >health_hazards_workbook.pdf
controlling workplace conditions that may cause workers' injury or illness. ... associated with the above health hazards in construction. Chemical. ▫ Gases.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Constantly connecting and disconnecting without any delay seems like it is asking for trouble in the OS Bluetooth stack. We also don’t recommend reusing the same BleakClient object after disconnecting since it will be in an inconsistent state.
I think I have found the solution to this problem.
The problem was that
asyncio.CancelledError
is not a subclass ofException
but a subclass ofBaseException
, thus the exception was not handled. I addedexcept asyncio.CancelledError as e:
into the exception handlings and the program continued to work after the exception happened.I think it could be useful to add this into the Bleak examples or into the Readme.