jbouwh / incomfort-client

Python client to poll Intergas boilers via a Lan2RF gateway
MIT License
5 stars 2 forks source link

[python 3.12] aiohttp raises a RuntimeError because the event loop does not run #38

Open ygrange opened 1 month ago

ygrange commented 1 month ago

In Python 3.12 asyncio seems to have broken the behaviour of getting a session while the event loop is not running.

I am not really used to async stuff so I am not sure what the best way to sove it, but for now my workaround is to

async def _clientsession():
   return await aiohttp.ClientSession()

and then replace

self._session = session if session else  aiohttp.ClientSession()

by

self._session = session if session else _clientsession()

(I could do an MR but this is a quick fix and you may have a nicer way to fix this :))

ygrange commented 1 month ago

(I am not sure if I fixed it because now I end up with async objects; not sure what to expect though)

jbouwh commented 1 month ago

The session is created in the constructor, so awaiting is only possible using a an executor job within the event loop. Here we only create an object. Nothing can be awaited as ClientSession is an object that is constructed as well.

When using the library, make sure the event loop is running.