Replies: 2 comments
-
Ok, I think I found it, it seems that the difference is in the implicit calls to aenter() and aexit(), and that the code below does work. Am I missing something? async def test3():
print(f"Trying to connect to {device_address}", flush=True)
device = await BleakScanner.find_device_by_address(device_address, timeout=10.0)
assert device
client = BleakClient(device)
assert client.is_connected()
await client.__aenter__() ## <---
print(f"Connected", flush=True)
service = client.services.get_service("6b6a78d7-8ee0-4a26-ba7b-62e357dd9720")
assert(service)
await client.__aexit__(None, None, None) ## <--- |
Beta Was this translation helpful? Give feedback.
0 replies
-
Ok, this thread ends up with the obvious, but I don't know how to delete it. aenter() and aexit() are equivalent to connect(), disconnect(). |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I have the two test programs below that are supposed to do the same thing. Test1 does use 'async with' and works while Test2 which doesn't user 'async with' doesn't and throws a Service Discovery has not been performed yet exception. My question is, is it possible to modify test2 to work without using the 'async with' clause? My application is based on the the pyqtgraph frameworks and runs on callback from the framework such that I can't have my own main with 'async with'.
I will also appreciate some insight what does the 'async with' provide, I guess some life cycle management but I could not find python documentation that I could understand.
Beta Was this translation helpful? Give feedback.
All reactions