`ib`: drop use of `_account2clients` in `load_clients_for_trio()`

Instead adjust `load_aio_clients()` to only reload clients detected as
non-loaded or disconnected (2 birds), and avoid use of the global module
table which could result in stale disconnected clients persisting on
multiple `brokerd` client reconnects, resulting in error.
pre_overruns_ctxcancelled
Tyler Goodlet 2023-03-23 12:16:21 -04:00
parent 8ee3fc4aa5
commit 366de901df
1 changed files with 15 additions and 16 deletions

View File

@ -387,8 +387,7 @@ class Client:
bar_size, duration, dt_duration = _samplings[sample_period_s]
global _enters
# log.info(f'REQUESTING BARS {_enters} @ end={end_dt}')
print(
log.info(
f"REQUESTING {duration}'s worth {bar_size} BARS\n"
f'{_enters} @ end={end_dt}"'
)
@ -730,7 +729,7 @@ class Client:
)
elif (
exch in ('IDEALPRO')
exch in {'IDEALPRO'}
or sectype == 'CASH'
):
# if '/' in symbol:
@ -1199,9 +1198,14 @@ async def load_aio_clients(
for host, port in combos:
sockaddr = (host, port)
maybe_client = _client_cache.get(sockaddr)
if (
sockaddr in _client_cache
or sockaddr in _scan_ignore
sockaddr in _scan_ignore
or (
maybe_client
and maybe_client.ib.isConnected()
)
):
continue
@ -1307,19 +1311,13 @@ async def load_clients_for_trio(
a ``tractor.to_asyncio.open_channel_from()``.
'''
global _accounts2clients
async with load_aio_clients() as accts2clients:
if _accounts2clients:
to_trio.send_nowait(_accounts2clients)
to_trio.send_nowait(accts2clients)
# TODO: maybe a sync event to wait on instead?
await asyncio.sleep(float('inf'))
else:
async with load_aio_clients() as accts2clients:
to_trio.send_nowait(accts2clients)
# TODO: maybe a sync event to wait on instead?
await asyncio.sleep(float('inf'))
@acm
async def open_client_proxies() -> tuple[
@ -1517,7 +1515,8 @@ async def open_client_proxy(
# mock all remote methods on ib ``Client``.
for name, method in inspect.getmembers(
Client, predicate=inspect.isfunction
Client,
predicate=inspect.isfunction,
):
if '_' == name[0]:
continue