# How to use asyncio based library like aiohttp

**URL:** <https://forum.robotframework.org/t/how-to-use-asyncio-based-library-like-aiohttp/8415>\
**Category:** Libraries\
**Created:** [6 February 2025 12:32 UTC](https://forum.robotframework.org/t/how-to-use-asyncio-based-library-like-aiohttp/8415 "2025-02-06T12:32:10Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![machielse](https://avatars.discourse-cdn.com/v4/letter/m/eb9ed0/32.png) [@machielse](https://forum.robotframework.org/u/machielse)\
**Post date:** [6 February 2025 12:32 UTC](https://forum.robotframework.org/t/how-to-use-asyncio-based-library-like-aiohttp/8415/1 "2025-02-06T12:32:10Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![machielse](https://avatars.discourse-cdn.com/v4/letter/m/eb9ed0/32.png) [@machielse](https://forum.robotframework.org/u/machielse)\
**Post date:** [7 February 2025 14:24 UTC](https://forum.robotframework.org/t/how-to-use-asyncio-based-library-like-aiohttp/8415/3 "2025-02-07T14:24:43Z")

</div>

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.
