-
Notifications
You must be signed in to change notification settings - Fork 300
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Client.disconnect() hangs with Windows 10 #1648
Comments
I had a Windows computer that took a very long time to disconnect. I ended up reinstalling Windows and it fixed the problem. |
Unfortunately, the problem is existing on Windows 11 too, but my main project is based on Windows 10. Secondly, the device do disconnect. Debug shows device loses connection, my device indicates disconnecting with LED and device's serial port shows BLE commands for disconnect handle. Everything shows device is disconnected, but your library's event is never set. I can make disconnect timeout longer, but it won't help, as your library variables shows device is disconencted, as I mentioned in my post. I cannot do reinstaling of operating system, because problem concerns multiple PCs, at least one with Windows 11 (but I didn't want to make different post, as the solution for windows 11 is probably same as for windows 10). I would block work of many colleagues just to arrive at the same point that it's something in library. If you can, please write where (which file and line) you do event.set() for disconnect() and I will try debugging more. Unfortunately I'm not very familiar with async functions, so I cannot back-engineer where event.set() should be called |
Tkinter doesn't integrate well with asyncio, so it could be that tkinter is blocking the disconnect event. You could try this example code to see if you see the same problem: https://github.com/hbldh/bleak/blob/develop/examples/disconnect_callback.py |
I tried https://github.com/hbldh/bleak/blob/develop/examples/disconnect_callback.py, and it freezes when disconnecting. In fact, the same code was working fine a few weeks ago. I strongly suspect that some update has been made to Windows during this time. I tried both on Windows 10 and Windows 11 However, if I use https://github.com/hbldh/bleak/blob/develop/examples/enable_notifications.py, the disconnection works normally. |
Are there any news on this issue? I'm also having this problem on latest Win11 version. I perform a loopback test, in which I continuously send packages to the device and it sends them back to me. I use asyncio.Queues to buffer the data from read and write, like some of the examples. The disconnect call can take a few seconds, to more than 10 minutes. I have no idea how to fix this issue. Any clues? |
It is lacking a reproducible test case or sufficient logs to be able to tell what the different is between working and not working cases. Logging Bluetooth packets with Wireshark as describe in the troubleshooting guide is always the best way to see what is going on at a low level. |
In my case, I found that the packages were piling up on the lower levels of the stack. Even after terminating the application, Windows would still keep sending the enqueued packages until they were all sent. The only way to stop it is by turning the bluetooth off. I solved it by controlling the amount of enqueued packages, only writing more when some amount was already sent back by the device. By doing that, disconnect now takes roughly the same time as if no data was sent. Hope this helps. Thanks. |
That is useful information to know, thanks for following up. |
Description
After invoking client.disconnect() it hangs on function. It does reconnect (I have LED status on my device for connection status) and with debugging every variable show device does indeed disconnect. Nevertheless the function doesn't end correctly, it always reaches async timeout. I cannot use winrt library as I have too new Python version. I'm reluctant to downgrade Python version.
What I Did
Here is main code for disconnecting. The code never reaches beyond single_client.disconnect(). It caches Exception, it doesn't print exception cause, but raises Timeout Exception.
Beside this I did debugging of winrt/client.py and self._requester property and self.is_connected shows device is disconnected after about 30 seconds. I tried adding asyncio.sleep before self._requester.close(), but it didn't help. I tried doing this: https://stackoverflow.com/questions/71557849/listing-connected-ble-devices-from-cpython-in-windows but it doesn't work (first function always gives empty list).
Logs
Here is info about my BLE driver:
and below are logs from debug:
For safety reasons I changed correct paths to "my_path", as the error is not depending on path.
Because of the error my app hangs and I need to forcefully kill it (which is bad, as I should invoke disconnect devices on closing app). If I close my app without prior device disconnecting library does correct closing connection.
Is it the problem in your library and you can fix it or is it in winrt one and I do need to downgrade Python version?
The text was updated successfully, but these errors were encountered: