How to use asyncio based library like aiohttp

since python 3.12 we have been experiencing issues with our current python backend libraries that are using asyncio libs like aiohttp and aiocoap. As there’s not a lot documentation, or at least I didn’t find it, could someone give me some pointers on how to use this. Currently getting errors like; no event loop, or not receiving any data in tasks wich are supposed to run in the background.

mostly struggling when to use asyncio.run or use
loop = asyncio.get_running_loop()
loop.run_until_complete(self._socket.send_json(msg))

The first works but I find it difficult to get returns from a background task that should fire when receiving data. The second gives issues as it sometimes states no event loop.
Call stack in vscode shows an asyncio thread but …

Any help appreciated
Cheers
Edwin

Hi Feni,

thanks for your information.
I’ve used asyncio.run on top-level async operations and that is working. Tip is that the run command should handle all inside that command. (all meaning: connection setup, communicate and close)
For the websocket server and http server. I’ve started them on a separate thread with own event loop. That allowed me to use tasks and queues with asyncio.run_coroutine_threadsafe() to run routines from robotframework on the correct event loops.

1 Like