-
-
Notifications
You must be signed in to change notification settings - Fork 616
Description
Hi there.
I have Socket.IO client on JS and python-socketio AsyncServer under Tornado (i have tornado-app, use get_tornado_handler and async_mode set to tornado) server.
Versions: python 3.6, tornado 6.0.1, socketio 4.5.1).
For example, I have some handlers in server, which set in constructor:
class MySocketClass(socketio.AsyncServer):
executor = ThreadPoolExecutor(20)
_thread_pool = executor
def __init__(self, _impl):
super().__init__(async_mode='tornado')
impl = _impl
self.on('syncTest', self.message_sync)
self.on('asyncTest1', self.message_a1)
self.on('asyncTest2', self.message_a2)
self.on('asyncTest3', self.message_a3)
def message_sync(self):
return None, "Synchronous message"
# five seconds to work
async def message_a0(self, *args):
params = args[1]
res = await tornado.ioloop.IOLoop.current().run_in_executor(self._thread_pool,
functools.partial(impl.internal_message_0, params)
return None, res
# seven seconds to work
async def message_a1(self, *args):
params = args[1]
res = await tornado.ioloop.IOLoop.current().run_in_executor(self._thread_pool,
functools.partial(impl.internal_message_1, params)
return None, res
# one second to work
async def message_a2(self, *args):
params = args[1]
res = await tornado.ioloop.IOLoop.current().run_in_executor(self._thread_pool,
functools.partial(impl.internal_message_2, params)
return None, res
self._thread_pool is concurrent.futures.ThreadPoolExecutor and implementation methods working in another threads.
Socket.IO client send 3 messages simultaneously (message_a0, message_a1 and message_a2, I have logging about sending).
My expectations are next:
- SocketIO client get response for message_a3 (as fastest);
- SocketIO client get response for message_a1 (as mid-speed);
- SocketIO client get response for message_a2 (as slowest);
But I see that my handlers for message_a2 and message_a3 doesn't start before ending previous (in debugger I see that these events aren't triggering while message_a1 is working).
async_handlers flag set to True. I see that we call start_background_task(), but everything work in main thread and sequentially. But I want run some handlers concurrently (which aren't use shared resources).
I found this issue, but it doesn't help me.
What should I do differently in my solution (and if it's using Tornado, how keep Tornado-server and achieve my expectations)?
Thanks in advance!