Using websockets with QtAsyncio
-
The documentation states that:
"We consider that this API consists of two levels:
- Fundamental infrastructure for event loops and asynchronous operations, including futures, tasks, handles, executors, and event loop management functions (see below).
- A user-facing API for use in applications, including transports and protocols, network connections, servers, sockets, signals, subprocesses.
QtAsyncio currently covers the first level. This includes the following functions, for which the API is identical with QtAsyncio as with asyncio"
I didn't understand the significance of this, until I tried to use websockets in my code using QtAsyncio as the event loop:
async def my_coroutine(): while True: print("Running coroutine") await asyncio.sleep(1) # Simulate non-blocking operation async with connect("ws://localhost:8765") as websocket: await asyncio.sleep(5)
The code is just to illustrate the error, which is:
NotImplementedError: QAsyncioEventLoop.create_connection() is not implemented yet
I've been messing around with separate Threads running their own event loops. I need to have a slot respond to a signal and send out a websocket message.
Would it make sense to have the signal handling socket running in a separate Thread that uses an asyncio event loop, or is there a more elegant workaraound for this?