Is it possible to replace the loop created from asyncio with QtAsyncio?

47 Views Asked by At

I'm trying to use the QtAsyncio library in pyside 6 and with the python-snapcast library and i can't manage to find a way to replace the asyncio loop that the create_server function necessitates with something from QtAsyncio

I tried to use QtAsyncio.run since it creates the loop by itself but the create_server function necessitates a variable with the loop.

server = QtAsyncio.run(create_server(ip_value))

this is the normal implementation with asycnio

server = loop.run_until_complete(create_server(loop, 'localhost'))
1

There are 1 best solutions below

0
jsbueno On

You can get the running loop by calling get_running_loop. Just put a small wrapper around your create_server call to retrieve the loop:

import asyncio
import QtAsyncio

async def wrapper(hostname):
    loop = asyncio.get_running_loop
    return await create_server(loop, hostname)

...

QtAsyncio.run(wrapper("localhost"))