Support no-disconnect on `open_aio_clients()` exit
Allows for easier restarts of certain `trio` side tasks without killing the `asyncio`-side clients; support via flag. Also fix a bug in `Client.bars()`: we need to return the duration on the empty bars case..ib_1m_hist
parent
23d0353934
commit
90a395a069
|
@ -412,7 +412,7 @@ class Client:
|
||||||
# ``end_dt`` which exceeds the ``duration``,
|
# ``end_dt`` which exceeds the ``duration``,
|
||||||
# - a timeout occurred in which case insync internals return
|
# - a timeout occurred in which case insync internals return
|
||||||
# an empty list thing with bars.clear()...
|
# an empty list thing with bars.clear()...
|
||||||
return [], np.empty(0)
|
return [], np.empty(0), dt_duration
|
||||||
# TODO: we could maybe raise ``NoData`` instead if we
|
# TODO: we could maybe raise ``NoData`` instead if we
|
||||||
# rewrite the method in the first case? right now there's no
|
# rewrite the method in the first case? right now there's no
|
||||||
# way to detect a timeout.
|
# way to detect a timeout.
|
||||||
|
@ -1086,6 +1086,7 @@ async def load_aio_clients(
|
||||||
# retry a few times to get the client going..
|
# retry a few times to get the client going..
|
||||||
connect_retries: int = 3,
|
connect_retries: int = 3,
|
||||||
connect_timeout: float = 0.5,
|
connect_timeout: float = 0.5,
|
||||||
|
disconnect_on_exit: bool = True,
|
||||||
|
|
||||||
) -> dict[str, Client]:
|
) -> dict[str, Client]:
|
||||||
'''
|
'''
|
||||||
|
@ -1227,10 +1228,11 @@ async def load_aio_clients(
|
||||||
finally:
|
finally:
|
||||||
# TODO: for re-scans we'll want to not teardown clients which
|
# TODO: for re-scans we'll want to not teardown clients which
|
||||||
# are up and stable right?
|
# are up and stable right?
|
||||||
for acct, client in _accounts2clients.items():
|
if disconnect_on_exit:
|
||||||
log.info(f'Disconnecting {acct}@{client}')
|
for acct, client in _accounts2clients.items():
|
||||||
client.ib.disconnect()
|
log.info(f'Disconnecting {acct}@{client}')
|
||||||
_client_cache.pop((host, port), None)
|
client.ib.disconnect()
|
||||||
|
_client_cache.pop((host, port), None)
|
||||||
|
|
||||||
|
|
||||||
async def load_clients_for_trio(
|
async def load_clients_for_trio(
|
||||||
|
|
Loading…
Reference in New Issue