From 04e21a96da5cf3cbf58fc92158f97abacbc769fa Mon Sep 17 00:00:00 2001 From: Tyler Goodlet Date: Wed, 19 Aug 2020 07:41:18 -0400 Subject: [PATCH] Use partial, pass kwargs to `tractor._main()` --- piker/ui/_exec.py | 26 +++++++++++--------------- piker/ui/cli.py | 10 +++++++++- 2 files changed, 20 insertions(+), 16 deletions(-) diff --git a/piker/ui/_exec.py b/piker/ui/_exec.py index 7a137fed..c169640d 100644 --- a/piker/ui/_exec.py +++ b/piker/ui/_exec.py @@ -4,8 +4,9 @@ Trio - Qt integration Run ``trio`` in guest mode on top of the Qt event loop. All global Qt runtime settings are mostly defined here. """ +from functools import partial import traceback -from typing import Tuple, Callable, Dict +from typing import Tuple, Callable, Dict, Any import PyQt5 # noqa from pyqtgraph import QtGui @@ -31,8 +32,8 @@ class MainWindow(QtGui.QMainWindow): def run_qtractor( func: Callable, args: Tuple, - kwargs: Dict, main_widget: QtGui.QWidget, + tractor_kwargs: Dict[str, Any] = {}, window_type: QtGui.QMainWindow = MainWindow, ) -> None: # avoids annoying message when entering debugger from qt loop @@ -90,26 +91,21 @@ def run_qtractor( } # setup tractor entry point args - args = ( - # async_fn - func, - # args (always append widgets list) - args + (widgets,), - # kwargs - kwargs, - # arbiter_addr - ( + main = partial( + tractor._main, + async_fn=func, + args=args + (widgets,), + arbiter_addr=( tractor._default_arbiter_host, tractor._default_arbiter_port, ), - # name - 'qtractor', + name='qtractor', + **tractor_kwargs, ) # guest mode trio.lowlevel.start_guest_run( - tractor._main, - *args, + main, run_sync_soon_threadsafe=run_sync_soon_threadsafe, done_callback=done_callback, ) diff --git a/piker/ui/cli.py b/piker/ui/cli.py index c1052733..74a3cae3 100644 --- a/piker/ui/cli.py +++ b/piker/ui/cli.py @@ -63,6 +63,7 @@ def monitor(config, rate, name, dhost, test, tl): name='monitor', loglevel=loglevel if tl else None, rpc_module_paths=['piker.ui.kivy.monitor'], + debug_mode=True, ) @@ -118,4 +119,11 @@ def chart(config, symbol, date, rate, test): brokername = config['broker'] tractorloglevel = config['tractorloglevel'] - _main(sym=symbol, brokername=brokername, loglevel=tractorloglevel) + _main( + sym=symbol, + brokername=brokername, + tractor_kwargs={ + 'debug_mode': True, + 'loglevel': tractorloglevel, + }, + )