mirror of
https://github.com/tiqi-group/pydase.git
synced 2025-06-07 05:50:41 +02:00
refactoring: moving initialisation of socketio client into separate function
This commit is contained in:
parent
5dec01d800
commit
9920350753
@ -134,6 +134,16 @@ class Client:
|
|||||||
|
|
||||||
def connect(self, block_until_connected: bool = True) -> None:
|
def connect(self, block_until_connected: bool = True) -> None:
|
||||||
if self._thread is None or self._loop is None:
|
if self._thread is None or self._loop is None:
|
||||||
|
self._initialize_socketio_client()
|
||||||
|
self._loop = self._initialize_loop_and_thread()
|
||||||
|
|
||||||
|
connection_future = asyncio.run_coroutine_threadsafe(
|
||||||
|
self._connect(), self._loop
|
||||||
|
)
|
||||||
|
if block_until_connected:
|
||||||
|
connection_future.result()
|
||||||
|
|
||||||
|
def _initialize_socketio_client(self) -> None:
|
||||||
if self._proxy_url is not None:
|
if self._proxy_url is not None:
|
||||||
session = aiohttp.ClientSession(
|
session = aiohttp.ClientSession(
|
||||||
connector=aiohttp_socks.connector.ProxyConnector.from_url(
|
connector=aiohttp_socks.connector.ProxyConnector.from_url(
|
||||||
@ -147,14 +157,6 @@ class Client:
|
|||||||
else:
|
else:
|
||||||
self._sio = socketio.AsyncClient(**self._sio_client_kwargs)
|
self._sio = socketio.AsyncClient(**self._sio_client_kwargs)
|
||||||
|
|
||||||
self._loop = self._initialize_loop_and_thread()
|
|
||||||
|
|
||||||
connection_future = asyncio.run_coroutine_threadsafe(
|
|
||||||
self._connect(), self._loop
|
|
||||||
)
|
|
||||||
if block_until_connected:
|
|
||||||
connection_future.result()
|
|
||||||
|
|
||||||
def _initialize_loop_and_thread(self) -> asyncio.AbstractEventLoop:
|
def _initialize_loop_and_thread(self) -> asyncio.AbstractEventLoop:
|
||||||
"""Initialize a new asyncio event loop, start it in a background thread,
|
"""Initialize a new asyncio event loop, start it in a background thread,
|
||||||
and create the ProxyClass instance bound to that loop.
|
and create the ProxyClass instance bound to that loop.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user