Make option chain spawnable as a subactor

Look up the broker module and set up the loglevel locally.
Ask the arbiter for a portal to the data daemon since we can't
pass one to a subactor by reference.
kivy_mainline_and_py3.8
Tyler Goodlet 2019-03-21 21:50:55 -04:00
parent fc1e63b2c1
commit 3bbb1db2b4
1 changed files with 28 additions and 19 deletions

View File

@ -15,8 +15,9 @@ from kivy.app import async_runTouchApp
from kivy.core.window import Window from kivy.core.window import Window
from kivy.uix.label import Label from kivy.uix.label import Label
from ..log import get_logger from ..log import get_logger, get_console_log
from ..brokers.data import DataFeed from ..brokers.data import DataFeed
from ..brokers import get_brokermod
from .pager import PagerView from .pager import PagerView
from .tabular import Row, HeaderCell, Cell, TickerTable from .tabular import Row, HeaderCell, Cell, TickerTable
@ -408,7 +409,7 @@ class OptionChain(object):
self.render_rows(records, displayables) self.render_rows(records, displayables)
with trio.open_cancel_scope() as cs: with trio.CancelScope() as cs:
self._update_cs = cs self._update_cs = cs
await self._nursery.start( await self._nursery.start(
partial( partial(
@ -479,28 +480,36 @@ async def new_chain_ui(
async def _async_main( async def _async_main(
symbol: str, symbol: str,
portal: tractor._portal.Portal, brokername: str,
brokermod: types.ModuleType,
rate: int = 1, rate: int = 1,
loglevel: str = 'info',
test: bool = False test: bool = False
) -> None: ) -> None:
'''Launch kivy app + all other related tasks. '''Launch kivy app + all other related tasks.
This is started with cli cmd `piker options`. This is started with cli cmd `piker options`.
''' '''
if loglevel is not None:
get_console_log(loglevel)
brokermod = get_brokermod(brokername)
async with trio.open_nursery() as nursery: async with trio.open_nursery() as nursery:
# set up a pager view for large ticker lists # get a portal to the data feed daemon
chain = await new_chain_ui( async with tractor.wait_for_actor('brokerd') as portal:
portal,
symbol, # set up a pager view for large ticker lists
brokermod, chain = await new_chain_ui(
rate=rate, portal,
) symbol,
async with chain.open_rt_display(nursery, symbol): brokermod,
try: rate=rate,
await async_runTouchApp(chain.widgets['root']) )
finally: async with chain.open_rt_display(nursery, symbol):
if chain._quote_gen: try:
await chain._quote_gen.aclose() await async_runTouchApp(chain.widgets['root'])
# cancel GUI update task finally:
nursery.cancel_scope.cancel() if chain._quote_gen:
await chain._quote_gen.aclose()
# cancel GUI update task
nursery.cancel_scope.cancel()