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

Please add an example of using Bleak from a non async function? #826

Closed
zapta opened this issue May 7, 2022 · 4 comments
Closed

Please add an example of using Bleak from a non async function? #826

zapta opened this issue May 7, 2022 · 4 comments
Labels
Documentation Issues or PRs relating to RTD or documentation

Comments

@zapta
Copy link

zapta commented May 7, 2022

Bleaks API is based on async functions which makes it difficult to use from non async function. Please add an example where a non async main reads and print a value from a device.

In my case, the non async caller is a callback from a GUI framework which must be non async.

@dhalbert
Copy link

dhalbert commented May 7, 2022

I did this several years ago when encountering the same problem:
https://github.com/adafruit/Adafruit_Blinka_bleio/blob/a7d037244956a2d77e99250f76c11f9660d46386/_bleio/common.py#L136-L140. I am not sure it is the right way to do it these days.

@zapta
Copy link
Author

zapta commented May 7, 2022

Thanks. I also got this https://stackoverflow.com/questions/72155012/how-to-call-an-async-python-function-from-a-non-async-function.

I think it worth having an explicit example with the recommended way to call Bleak from sync function.

@dlech dlech added the Documentation Issues or PRs relating to RTD or documentation label Jul 13, 2022
@dlech
Copy link
Collaborator

dlech commented Oct 3, 2022

Calling async code from non-async is outside of the scope of bleak and not a use case we want to spend time supporting. If you don't want to use asyncio, you should probably consider using a different library, for example, https://github.com/OpenBluetoothToolbox/SimpleBLE looks promising.

@dlech dlech closed this as completed Oct 3, 2022
@lidorshimoni
Copy link

I did this several years ago when encountering the same problem: https://github.com/adafruit/Adafruit_Blinka_bleio/blob/a7d037244956a2d77e99250f76c11f9660d46386/_bleio/common.py#L136-L140. I am not sure it is the right way to do it these days.

This worked for me!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Documentation Issues or PRs relating to RTD or documentation
Projects
None yet
Development

No branches or pull requests

4 participants