question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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:closed
  • Created 2 years ago
  • Comments:5

github_iconTop GitHub Comments

1reaction
dlechcommented, Mar 22, 2022

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.

0reactions
andraskalmarcommented, Mar 25, 2022

I think I have found the solution to this problem.

The problem was that asyncio.CancelledError is not a subclass of Exception but a subclass of BaseException, thus the exception was not handled. I added except 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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found