Spawn broker-daemon without asking

kivy_mainline_and_py3.8
Tyler Goodlet 2018-04-20 00:49:34 -04:00
parent 2973b40946
commit 0add443e8b
1 changed files with 18 additions and 17 deletions

View File

@ -126,7 +126,7 @@ def quote(loglevel, broker, tickers, df_output):
@click.option('--rate', '-r', default=5, help='Logging level') @click.option('--rate', '-r', default=5, help='Logging level')
@click.argument('name', nargs=1, required=True) @click.argument('name', nargs=1, required=True)
def watch(loglevel, broker, rate, name): def watch(loglevel, broker, rate, name):
"""Spawn a watchlist. """Spawn a real-time watchlist.
""" """
from .ui.watchlist import _async_main from .ui.watchlist import _async_main
log = get_console_log(loglevel) # activate console logging log = get_console_log(loglevel) # activate console logging
@ -145,12 +145,15 @@ def watch(loglevel, broker, rate, name):
client = Client(('127.0.0.1', 1616), subscribe) client = Client(('127.0.0.1', 1616), subscribe)
start = time.time() start = time.time()
down = False
while True: while True:
try: try:
await client.connect() await client.connect()
break break
except OSError as oserr: except OSError as oserr:
log.info("Waiting on daemon to come up...") if not down:
log.info("Waiting on daemon to come up...")
down = True
await trio.sleep(0.1) await trio.sleep(0.1)
if time.time() - start > timeout: if time.time() - start > timeout:
raise raise
@ -162,24 +165,22 @@ def watch(loglevel, broker, rate, name):
brokermod, rate brokermod, rate
) )
# signal exit of stream handler task
await client.aclose()
try: try:
trio.run(main) trio.run(main)
except OSError as oserr: except OSError as oserr:
log.exception(oserr) log.error(oserr)
answer = input( log.info("Spawning local broker-daemon...")
"\nWould you like to spawn a broker daemon locally? [Y/n]") child = Process(
if answer is not 'n': target=run,
child = Process( args=(_daemon_main, loglevel),
target=run, daemon=True,
args=(_daemon_main, loglevel), )
daemon=True, child.start()
) trio.run(main, 5)
child.daemon = True child.join()
child.start()
trio.run(main, 5)
# trio dies with a keyboard interrupt
os.kill(child.pid, signal.SIGINT)
child.join()
@cli.group() @cli.group()