bimmer_connected: Asyncio use leads to "runtime error"
Describe the issue
Hi Rikroe, I decided to open the error here instead of continuing on the discussion #422. I am using the version 0.9.0.0b6 integrated in Domoticz. All works fine, however systematically after 1-2 hours, I got the following errors. I retrieve the car status in loop by using the following (cleaned) code in a loop:
if self.myBMW:
self.myVehicle = None
try:
asyncio.run(self.myBMW.get_vehicles())
except:
import traceback
Domoticz.Debug('StatusUpdate TRACEBACK: {}'.format(traceback.format_exc()))
else:
self.myVehicle = self.myBMW.get_vehicle(Parameters['Mode4'])
if self.myVehicle:
Domoticz.Debug('Car {} found after update!'.format(self.myVehicle.name))
The get_vehicles()
generates at a certain moment the error below (traceback). And the same error appears at every call from then on. When restarting completely the plugin all works fine again.
2022-04-25 20:53:33.064 TestBmw: Handling task: StatusUpdate.
2022-04-25 20:53:33.145 TestBmw: StatusUpdate TRACEBACK: Traceback (most recent call last):
File "/home/filip/domoticz/plugins/Bmw/plugin.py", line 280, in handleTasks
asyncio.run(self.myBMW.get_vehicles())
File "/usr/lib/python3.9/asyncio/runners.py", line 44, in run
return loop.run_until_complete(main)
File "/usr/lib/python3.9/asyncio/base_events.py", line 642, in run_until_complete
return future.result()
File "/usr/local/lib/python3.9/dist-packages/bimmer_connected/account.py", line 78, in get_vehicles
vehicles_responses: List[httpx.Response] = await asyncio.gather(*vehicles_tasks)
File "/usr/local/lib/python3.9/dist-packages/httpx/_client.py", line 1729, in get
return await self.request(
File "/usr/local/lib/python3.9/dist-packages/httpx/_client.py", line 1506, in request
return await self.send(request, auth=auth, follow_redirects=follow_redirects)
File "/usr/local/lib/python3.9/dist-packages/httpx/_client.py", line 1593, in send
response = await self._send_handling_auth(
File "/usr/local/lib/python3.9/dist-packages/httpx/_client.py", line 1621, in _send_handling_auth
response = await self._send_handling_redirects(
File "/usr/local/lib/python3.9/dist-packages/httpx/_client.py", line 1656, in _send_handling_redirects
await hook(request)
File "/usr/local/lib/python3.9/dist-packages/bimmer_connected/api/client.py", line 39, in update_request_header
request.headers["authorization"] = await self.config.authentication.get_authentication()
File "/usr/local/lib/python3.9/dist-packages/bimmer_connected/api/authentication.py", line 46, in get_authentication
await self.login()
File "/usr/local/lib/python3.9/dist-packages/bimmer_connected/api/authentication.py", line 72, in login
async with self._lock:
File "/usr/lib/python3.9/asyncio/locks.py", line 14, in __aenter__
await self.acquire()
File "/usr/lib/python3.9/asyncio/locks.py", line 120, in acquire
await fut
RuntimeError: Task <Task pending name='Task-237' coro=<AsyncClient.get() running at /usr/local/lib/python3.9/dist-packages/httpx/_client.py:1729> cb=[gather.<locals>._done_callback() at /usr/lib/python3.9/asyncio/tasks.py:766]> got Future <Future pending> attached to a different loop
2022-04-25 20:53:33.146 TestBmw: Finished handling task: StatusUpdate.
I will now try to simulate the same problem by a dedicated script outside Domoticz. test_asyncio.py.txt
Any idea so far?
Expected behavior
Which Home Assistant version are you using?
(used outside HA)
What was the last working version of Home Assistant Core?
No response
What is your region?
Rest of world
ConnectedDrive website
- I can still successfully login to the BMW ConnectedDrive website and the car status is available there.
- I have ConnectedDrive enabled for my vehicle.
Number of cars
- I have 2 or more cars linked to the ConnectedDrive account.
- I have a Mini vehicle linked to my account.
Output of bimmer_connected fingerprint
No response
Anything in the logs that might be useful for us?
No response
Additional information
No response
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 20 (9 by maintainers)
Just for your information and to say thank you again! Everything is still working like a charm since yesterday evening…