From 7e5e3c4cc6c45bffdb9619ec4c2b19e945320565 Mon Sep 17 00:00:00 2001 From: Tyler Goodlet Date: Wed, 16 May 2018 20:44:15 -0400 Subject: [PATCH] Adjust reconnect coro to swallow symbol data resp Couple fixes here: - if no tickers for a watchlist name -> bail - swallow the symbol data response in the reconnect handler coro - don't sleep 5 seconds before connecting to subproc daemon... Resolves #43 --- piker/cli.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/piker/cli.py b/piker/cli.py index 0ae1f5ce..7fa8edf5 100644 --- a/piker/cli.py +++ b/piker/cli.py @@ -126,14 +126,20 @@ def watch(loglevel, broker, rate, name, dhost): watchlist_from_file = wl.ensure_watchlists(_watchlists_data_path) watchlists = wl.merge_watchlist(watchlist_from_file, wl._builtins) tickers = watchlists[name] + if not tickers: + log.error(f"No symbols found for watchlist `{name}`?") + return async def launch_client(sleep=0.5, tries=10): async def subscribe(client): - # initial request for symbols price streams + # initial subs request for symbols await client.send((brokermod.name, tickers)) + # symbol data is returned in first response which we'll + # ignore on reconnect + await client.recv() - client = Client((dhost, 1616), subscribe) + client = Client((dhost, 1616), on_reconnect=subscribe) for _ in range(tries): # try for 5 seconds try: await client.connect() @@ -163,9 +169,10 @@ def watch(loglevel, broker, rate, name, dhost): target=run, args=(partial(_daemon_main, dhost), loglevel), daemon=True, + name='pikerd', ) child.start() - trio.run(launch_client, 5) + trio.run(partial(launch_client, tries=5)) child.join()