Don't bail when a sub-optschain crashes

kivy_mainline_and_py3.8
Tyler Goodlet 2019-03-24 12:09:17 -04:00
parent 8964b7a5fb
commit 1cc33abca0
2 changed files with 21 additions and 10 deletions

View File

@ -7,7 +7,6 @@ Launch with ``piker monitor <watchlist name>``.
""" """
from types import ModuleType, AsyncGeneratorType from types import ModuleType, AsyncGeneratorType
from typing import List, Callable from typing import List, Callable
from functools import partial
import trio import trio
import tractor import tractor
@ -146,6 +145,8 @@ async def update_quotes(
async def stream_symbol_selection(): async def stream_symbol_selection():
"""An RPC async gen for streaming the symbol corresponding """An RPC async gen for streaming the symbol corresponding
value corresponding to the last clicked row. value corresponding to the last clicked row.
Essentially of an event stream of clicked symbol values.
""" """
widgets = tractor.current_actor().statespace['widgets'] widgets = tractor.current_actor().statespace['widgets']
table = widgets['table'] table = widgets['table']
@ -235,14 +236,19 @@ async def _async_main(
""" """
from .option_chain import _async_main from .option_chain import _async_main
async with tractor.open_nursery() as tn: try:
await tn.run_in_actor( async with tractor.open_nursery() as tn:
'optschain', portal = await tn.run_in_actor(
_async_main, 'optschain',
symbol=table.last_clicked_row._last_record['symbol'], _async_main,
brokername=brokermod.name, symbol=table.last_clicked_row._last_record['symbol'],
# loglevel=tractor.log.get_loglevel(), brokername=brokermod.name,
) loglevel=tractor.log.get_loglevel(),
)
except tractor.RemoteActorError:
# don't allow option chain errors to crash this monitor
# this is, like, the most basic of resliency policies
log.exception(f"{portal.actor.name} crashed:")
async with trio.open_nursery() as nursery: async with trio.open_nursery() as nursery:
pager = PagerView( pager = PagerView(

View File

@ -384,8 +384,13 @@ class Row(HoverBehavior, GridLayout):
log.info(f"Pressed row for {self._last_record['symbol']}") log.info(f"Pressed row for {self._last_record['symbol']}")
if self.table and not self.is_header: if self.table and not self.is_header:
self.table.last_clicked_row = self self.table.last_clicked_row = self
symbol = self._last_record['symbol']
for sendchan in self.table._click_queues: for sendchan in self.table._click_queues:
sendchan.send_nowait(self._last_record['symbol']) try:
sendchan.send_nowait(symbol)
except trio.BrokenResourceError:
# indicates streaming client actor has terminated
log.warning("Symbol selection stream was already closed")
class TickerTable(GridLayout): class TickerTable(GridLayout):