commit bc2c978a47e37b2f4a9b2ee581acec2e454fe0cd Author: Illia Volochii illia.volochii@gmail.com Date: Sun Apr 26 21:46:41 2020 +0300
Start initializing the asynchronous controller in the dedicated thread --- stem/control.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/stem/control.py b/stem/control.py index 0105f9d4..3a687f1c 100644 --- a/stem/control.py +++ b/stem/control.py @@ -3908,9 +3908,15 @@ class Controller(_ControllerClassMethodMixin, _BaseControllerSocketMixin): self._asyncio_thread.setDaemon(True) self._asyncio_thread.start()
- self._async_controller = AsyncController(control_socket, is_authenticated) + self._async_controller = self._init_async_controller(control_socket, is_authenticated) self._socket = self._async_controller._socket
+ def _init_async_controller(self, control_socket: 'stem.socket.ControlSocket', is_authenticated: bool) -> 'stem.control.AsyncController': + async def init_async_controller(): + return AsyncController(control_socket, is_authenticated) + + return asyncio.run_coroutine_threadsafe(init_async_controller(), self._asyncio_loop).result() + def _execute_async_method(self, method_name: str, *args: Any, **kwargs: Any) -> Any: return asyncio.run_coroutine_threadsafe( getattr(self._async_controller, method_name)(*args, **kwargs),