Make pause/resume feed methods sync again

We can instead use the god widget's nursery to schedule all the feed
pause/resume requests and be even more concurrent during a view (of
symbols) switch.

Use `tractor.trionics.gather_contexts()` to start up the fsp and volume
chart-displays (for an additional conc speedup). Drop `dolla_vlm` again for
now until we figure out how we can display it *and* vlm on the same
sub-chart? It would be nice to avoid having to spawn an fsp process
before showing the volume curve.
py3.10_support
Tyler Goodlet 2021-12-22 08:30:22 -05:00
parent 8722cf4c49
commit 9c57f10e77
2 changed files with 42 additions and 49 deletions

View File

@ -229,7 +229,7 @@ class GodWidget(QWidget):
await trio.sleep(0) await trio.sleep(0)
# resume feeds *after* rendering chart view asap # resume feeds *after* rendering chart view asap
await chart.resume_all_feeds() chart.resume_all_feeds()
self.linkedsplits = linkedsplits self.linkedsplits = linkedsplits
symbol = linkedsplits.symbol symbol = linkedsplits.symbol
@ -361,7 +361,7 @@ class LinkedSplits(QWidget):
if not prop: if not prop:
# proportion allocated to consumer subcharts # proportion allocated to consumer subcharts
if ln < 2: if ln < 2:
prop = 1/(.375 * 6) prop = 1/3
elif ln >= 2: elif ln >= 2:
prop = 3/8 prop = 3/8
@ -631,8 +631,11 @@ class ChartPlotWidget(pg.PlotWidget):
**kwargs, **kwargs,
): ):
"""Configure chart display settings. '''
""" Configure initial display settings and connect view callback
handlers.
'''
self.view_color = view_color self.view_color = view_color
self.pen_color = pen_color self.pen_color = pen_color
@ -692,15 +695,13 @@ class ChartPlotWidget(pg.PlotWidget):
# for when the splitter(s) are resized # for when the splitter(s) are resized
self._vb.sigResized.connect(self._set_yrange) self._vb.sigResized.connect(self._set_yrange)
async def resume_all_feeds(self): def resume_all_feeds(self):
async with trio.open_nursery() as n: for feed in self._feeds.values():
for feed in self._feeds.values(): self.linked.godwidget._root_n.start_soon(feed.resume)
n.start_soon(feed.resume)
async def pause_all_feeds(self): def pause_all_feeds(self):
async with trio.open_nursery() as n: for feed in self._feeds.values():
for feed in self._feeds.values(): self.linked.godwidget._root_n.start_soon(feed.pause)
n.start_soon(feed.pause)
@property @property
def view(self) -> ChartView: def view(self) -> ChartView:

View File

@ -36,7 +36,7 @@ import trio
from .. import brokers from .. import brokers
from .._cacheables import maybe_open_context from .._cacheables import maybe_open_context
from ..trionics import async_enter_all from tractor.trionics import gather_contexts
from ..data.feed import open_feed, Feed from ..data.feed import open_feed, Feed
from ._chart import ( from ._chart import (
ChartPlotWidget, ChartPlotWidget,
@ -266,7 +266,7 @@ async def update_chart_from_quotes(
# chart isn't active/shown so skip render cycle and pause feed(s) # chart isn't active/shown so skip render cycle and pause feed(s)
if chart.linked.isHidden(): if chart.linked.isHidden():
await chart.pause_all_feeds() chart.pause_all_feeds()
continue continue
for sym, quote in quotes.items(): for sym, quote in quotes.items():
@ -601,9 +601,6 @@ async def start_fsp_displays(
group_status_key: str, group_status_key: str,
loglevel: str, loglevel: str,
# this con
display_in_own_task: bool = False,
) -> None: ) -> None:
''' '''
Create sub-actors (under flat tree) Create sub-actors (under flat tree)
@ -626,7 +623,7 @@ async def start_fsp_displays(
for (display_name, conf), (name, portal) in zip( for (display_name, conf), (name, portal) in zip(
fsps.items(), fsps.items(),
# rr to cluster for now.. # round robin to cluster for now..
cycle(cluster_map.items()), cycle(cluster_map.items()),
): ):
func_name = conf['func_name'] func_name = conf['func_name']
@ -925,16 +922,14 @@ async def maybe_open_vlm_display(
shm, opened = maybe_mk_fsp_shm( shm, opened = maybe_mk_fsp_shm(
linked.symbol.key, linked.symbol.key,
'$_vlm', 'vlm',
readonly=True, readonly=True,
) )
async with open_fsp_sidepane( async with open_fsp_sidepane(
linked, { linked, {
'vlm': { 'vlm': {
'params': { 'params': {
'price_func': { 'price_func': {
'default_value': 'chl3', 'default_value': 'chl3',
# tell target ``Edit`` widget to not allow # tell target ``Edit`` widget to not allow
@ -962,9 +957,6 @@ async def maybe_open_vlm_display(
# we do this internally ourselves since # we do this internally ourselves since
# the curve item internals are pretty convoluted. # the curve item internals are pretty convoluted.
style='step', style='step',
# original pyqtgraph flag for reference
# stepMode=True,
) )
# XXX: ONLY for sub-chart fsps, overlays have their # XXX: ONLY for sub-chart fsps, overlays have their
@ -999,7 +991,6 @@ async def display_symbol_data(
provider: str, provider: str,
sym: str, sym: str,
loglevel: str, loglevel: str,
order_mode_started: trio.Event, order_mode_started: trio.Event,
) -> None: ) -> None:
@ -1026,8 +1017,7 @@ async def display_symbol_data(
# group_key=loading_sym_key, # group_key=loading_sym_key,
# ) # )
async with async_enter_all( async with open_feed(
open_feed(
provider, provider,
[sym], [sym],
loglevel=loglevel, loglevel=loglevel,
@ -1035,11 +1025,8 @@ async def display_symbol_data(
# limit to at least display's FPS # limit to at least display's FPS
# avoiding needless Qt-in-guest-mode context switches # avoiding needless Qt-in-guest-mode context switches
tick_throttle=_quote_throttle_rate, tick_throttle=_quote_throttle_rate,
),
maybe_open_fsp_cluster(),
) as (feed, cluster_map):
) as feed:
ohlcv: ShmArray = feed.shm ohlcv: ShmArray = feed.shm
bars = ohlcv.array bars = ohlcv.array
symbol = feed.symbols[sym] symbol = feed.symbols[sym]
@ -1091,19 +1078,19 @@ async def display_symbol_data(
# TODO: eventually we'll support some kind of n-compose syntax # TODO: eventually we'll support some kind of n-compose syntax
fsp_conf = { fsp_conf = {
'dolla_vlm': { # 'dolla_vlm': {
'func_name': 'dolla_vlm', # 'func_name': 'dolla_vlm',
'zero_on_step': True, # 'zero_on_step': True,
'params': { # 'params': {
'price_func': { # 'price_func': {
'default_value': 'chl3', # 'default_value': 'chl3',
# tell target ``Edit`` widget to not allow # # tell target ``Edit`` widget to not allow
# edits for now. # # edits for now.
'widget_kwargs': {'readonly': True}, # 'widget_kwargs': {'readonly': True},
}, # },
}, # },
'chart_kwargs': {'style': 'step'} # 'chart_kwargs': {'style': 'step'}
}, # },
# 'rsi': { # 'rsi': {
# 'func_name': 'rsi', # literal python func ref lookup name # 'func_name': 'rsi', # literal python func ref lookup name
@ -1147,10 +1134,15 @@ async def display_symbol_data(
await trio.sleep(0) await trio.sleep(0)
vlm_chart = None vlm_chart = None
async with (
trio.open_nursery() as ln, async with gather_contexts(
maybe_open_vlm_display(linkedsplits, ohlcv) as vlm_chart, (
): trio.open_nursery(),
maybe_open_vlm_display(linkedsplits, ohlcv),
maybe_open_fsp_cluster(),
)
) as (ln, vlm_chart, cluster_map):
# load initial fsp chain (otherwise known as "indicators") # load initial fsp chain (otherwise known as "indicators")
ln.start_soon( ln.start_soon(
start_fsp_displays, start_fsp_displays,
@ -1164,7 +1156,7 @@ async def display_symbol_data(
loglevel, loglevel,
) )
# start graphics update loop(s)after receiving first live quote # start graphics update loop after receiving first live quote
ln.start_soon( ln.start_soon(
update_chart_from_quotes, update_chart_from_quotes,
linkedsplits, linkedsplits,