Skip to content
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

Timeouts for read_gatt_char/write_gatt_char #691

Closed
cflavio opened this issue Nov 25, 2021 · 2 comments
Closed

Timeouts for read_gatt_char/write_gatt_char #691

cflavio opened this issue Nov 25, 2021 · 2 comments
Assignees
Labels
Backend: BlueZ Issues and PRs relating to the BlueZ backend enhancement New feature or request

Comments

@cflavio
Copy link

cflavio commented Nov 25, 2021

  • bleak version: 0.12
  • Python version: 3.8
  • Operating System: Ubuntu 20.04
  • BlueZ version: 5.52

Description

Hi, I have observed that sometimes I have some invocations of read_gatt_char/write_gatt_char that never return. So, my application freezes. Is it the expected behavior? Is there a best practice for adding a timeout to them (so, if they don't return then something like an exception is raised and the control returns to the caller)?
Thank you very much!

@hbldh hbldh self-assigned this Nov 26, 2021
@hbldh hbldh added Backend: BlueZ Issues and PRs relating to the BlueZ backend enhancement New feature or request labels Nov 26, 2021
@hbldh
Copy link
Owner

hbldh commented Nov 26, 2021

There is no timeout capability in the dbus-next library that Bleak uses, but one could possibly use a await asyncio.wait_for(self._bus.call(...), timeout=5.0) (See Python docs) to stop waiting for a reply. I have no idea if this messes up the MessageBus that represents Bleak's connection to the DBus system which in turn communicates with BlueZ which in turn communicates with your device...

You can try it yourself by modifying in read_gatt_char and You can try it yourself by modifying in write_gatt_char. You should raise a BleakError if timeout happens and catch that in you application, instead of just returning None, though.

Try it and see if it works. Feel free to make a PR if you get it into a state that you are satified with, and we will review it!

@dlech
Copy link
Collaborator

dlech commented Jul 19, 2023

There is also now asyncio.timeout() which works better than asyncio.wait_for().

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Backend: BlueZ Issues and PRs relating to the BlueZ backend enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants