sio.call() almost hangs when calling from a different thread #1145
-
Hi there, my project is using socketio in asgi mode, basically the server receives a message from the client, executes a blocking code that also needs to talk to the client, and returns the response to the client. I'm currently running the blocking code in a different thread with a different loop using code like this: def _run_coroutine_in_thread(corofn, *args):
loop = asyncio.new_event_loop()
try:
coro = corofn(*args)
asyncio.set_event_loop(loop)
return loop.run_until_complete(coro)
finally:
loop.close()
async def run_plugin_task(sio, ...):
# ......
response = await sio.call(...)
# ......
async def handle_run_plugin(sid, data):
# ......
return await asyncio.get_event_loop().run_in_executor(None, _run_coroutine_in_thread, functools.partial(run_plugin_task, sio= self._client_sio, ......))
sio.on('run-plugin', handle_run_plugin, namespace='/daw') Here the |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
This is an invalid usage. You cannot use a different loop for the |
Beta Was this translation helpful? Give feedback.
This is an invalid usage. You cannot use a different loop for the
call()
, the entire Socket.IO collection of coroutines need to run under the same loop.