-
Notifications
You must be signed in to change notification settings - Fork 305
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
AttributeError: 'NoneType' object has no attribute 'Dispose' when disconnecting devices that have previously disconnected due to range/power off/etc #313
Comments
Gah... this is complex.... The Windows backend API has no dedicated disconnect function, so the only way I have found to facilitate a disconnect is by But in your example you call |
I agree, an explosion of some sort would be expected for trying to disconnect from something twice in a row, so I guess the real conundrum is why the first In the test case shown here, the problem only arises after a disconnect occurred remotely, so:
After using |
If Microsoft implemented the Dispose pattern correctly, it should disconnect without having to wait for the garbage collector. I have had the same experience that there is some delay after calling Dispose though, so I think we can conclude that it is not a synchronous operation. (In fact, there is a new DisposeAsync pattern being introduced in .NET because of issues like this.) Anyway, we could wait a while for a ConnectionStatusChanged event before returning from the async disconnect method to help ensure that the device had a chance to disconnect before allowing the program to move on. |
Hmm... I've been trying this with a different device and it disconnects right away when calling Dispose(). |
I will also suggest that multiple calls to Furthermore, |
This adds an event waiter so that `BleakClientDotNet.disconnect()` will actually await the disconnection event before returning. This is a partial fix for #313.
Yes, I agree. Multiple calls to disconnect should all yield the same I have not experienced problems with disconnecting on Windows since I added the |
Additional disconnect calls are now allowed in the released version 0.9.0. Will close this issue for now. |
Description
I've found a repeatable scenario wherein Bleak throws an AttributeError on attempting to
await client.disconnect()
a device which had previously disconnected itself and subsequently been reconnected to. I am not certain if this is a genuine issue or just a misuse of Bleak. In any case, catching the AttributeError still does not result in the ability to disconnect the device (it will just throw the same error each time).In short:
await client.disconnect()
What I Did
I put together a snippet that reproduces the problem for me; it requires a device where the BLE connection can quickly be severed on the device side and said device be ready to reconnect again quickly (other devices should work if the timings are adjusted to suit)
The text was updated successfully, but these errors were encountered: