mirror of
https://github.com/tiqi-group/pydase.git
synced 2025-06-06 13:30:41 +02:00
refactoring: moving initialisation of socketio client into separate function
This commit is contained in:
parent
5dec01d800
commit
9920350753
@ -134,19 +134,7 @@ 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:
|
||||||
if self._proxy_url is not None:
|
self._initialize_socketio_client()
|
||||||
session = aiohttp.ClientSession(
|
|
||||||
connector=aiohttp_socks.connector.ProxyConnector.from_url(
|
|
||||||
url=self._proxy_url, loop=self._loop
|
|
||||||
),
|
|
||||||
loop=self._loop,
|
|
||||||
)
|
|
||||||
self._sio = socketio.AsyncClient(
|
|
||||||
http_session=session, **self._sio_client_kwargs
|
|
||||||
)
|
|
||||||
else:
|
|
||||||
self._sio = socketio.AsyncClient(**self._sio_client_kwargs)
|
|
||||||
|
|
||||||
self._loop = self._initialize_loop_and_thread()
|
self._loop = self._initialize_loop_and_thread()
|
||||||
|
|
||||||
connection_future = asyncio.run_coroutine_threadsafe(
|
connection_future = asyncio.run_coroutine_threadsafe(
|
||||||
@ -155,6 +143,20 @@ class Client:
|
|||||||
if block_until_connected:
|
if block_until_connected:
|
||||||
connection_future.result()
|
connection_future.result()
|
||||||
|
|
||||||
|
def _initialize_socketio_client(self) -> None:
|
||||||
|
if self._proxy_url is not None:
|
||||||
|
session = aiohttp.ClientSession(
|
||||||
|
connector=aiohttp_socks.connector.ProxyConnector.from_url(
|
||||||
|
url=self._proxy_url, loop=self._loop
|
||||||
|
),
|
||||||
|
loop=self._loop,
|
||||||
|
)
|
||||||
|
self._sio = socketio.AsyncClient(
|
||||||
|
http_session=session, **self._sio_client_kwargs
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
self._sio = socketio.AsyncClient(**self._sio_client_kwargs)
|
||||||
|
|
||||||
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