From 4753dc2db8d641f02c8b6c41cb8a452ccb9f8dcb Mon Sep 17 00:00:00 2001 From: Tyler Goodlet Date: Mon, 14 Jan 2019 21:12:35 -0500 Subject: [PATCH] Alway teardown quote gen on exit --- piker/ui/monitor.py | 60 +++++++++++++++++++++------------------------ 1 file changed, 28 insertions(+), 32 deletions(-) diff --git a/piker/ui/monitor.py b/piker/ui/monitor.py index 18773da6..fafab986 100644 --- a/piker/ui/monitor.py +++ b/piker/ui/monitor.py @@ -140,8 +140,6 @@ async def update_quotes( log.debug("Waiting on quotes") log.warn("Data feed connection dropped") - # XXX: if we're cancelled this should never get called - # nursery.cancel_scope.cancel() async def stream_symbol_selection(): @@ -227,38 +225,36 @@ async def _async_main( table.bind(minimum_height=table.setter('height')) ss = tractor.current_actor().statespace - try: - async with trio.open_nursery() as nursery: - pager = PagerView( - container=box, - contained=table, - nursery=nursery - ) - box.add_widget(pager) - - widgets = { - 'root': box, - 'table': table, - 'box': box, - 'header': header, - 'pager': pager, - } - ss['widgets'] = widgets - nursery.start_soon( - update_quotes, - nursery, - brokermod.format_stock_quote, - widgets, - quote_gen, - feed._symbol_data_cache, - quotes - ) + async with trio.open_nursery() as nursery: + pager = PagerView( + container=box, + contained=table, + nursery=nursery + ) + box.add_widget(pager) + widgets = { + 'root': box, + 'table': table, + 'box': box, + 'header': header, + 'pager': pager, + } + ss['widgets'] = widgets + nursery.start_soon( + update_quotes, + nursery, + brokermod.format_stock_quote, + widgets, + quote_gen, + feed._symbol_data_cache, + quotes + ) + try: # Trio-kivy entry point. await async_runTouchApp(widgets['root']) # run kivy + finally: + # cancel remote data feed task + await quote_gen.aclose() # cancel GUI update task nursery.cancel_scope.cancel() - finally: - with trio.open_cancel_scope(shield=True): - # cancel aysnc gen call - await quote_gen.aclose()