Open hyansuper opened 2 years ago
I'm not aware of a better solution. asyncio is limited to at most one event loop per thread. This is by design. If you need concurrent event loops, you need to resort to multiple processes or multiple threads like you did.
You might be able to work around that using https://github.com/erdewit/nest_asyncio, but it should only be used for tests.
Does this answer you question?
thank you I think it will be convenient if there’s a decorator to run async function in a separate loop in its own thread, like
@pytest.mark.run_in_threaded_loop async def test_server(): ….
But i don’t know if it’s a very needed feature
It's worth investigating if this functionality can be added to the new _asyncio_eventloop mark (see #620). However, there should also be a discussion if this should be added.
To test the basic usage of websockets, I want to start a server and test the return string from client, I think server and client should be in separate thread.
The below code passed, but I just want to know if there's a proper/generalized way to do it?