Use partial, pass kwargs to `tractor._main()`

its_happening
Tyler Goodlet 2020-08-19 07:41:18 -04:00
parent 7acf7106df
commit 2f89979d8c
2 changed files with 20 additions and 16 deletions

View File

@ -4,8 +4,9 @@ Trio - Qt integration
Run ``trio`` in guest mode on top of the Qt event loop. Run ``trio`` in guest mode on top of the Qt event loop.
All global Qt runtime settings are mostly defined here. All global Qt runtime settings are mostly defined here.
""" """
from functools import partial
import traceback import traceback
from typing import Tuple, Callable, Dict from typing import Tuple, Callable, Dict, Any
import PyQt5 # noqa import PyQt5 # noqa
from pyqtgraph import QtGui from pyqtgraph import QtGui
@ -31,8 +32,8 @@ class MainWindow(QtGui.QMainWindow):
def run_qtractor( def run_qtractor(
func: Callable, func: Callable,
args: Tuple, args: Tuple,
kwargs: Dict,
main_widget: QtGui.QWidget, main_widget: QtGui.QWidget,
tractor_kwargs: Dict[str, Any] = {},
window_type: QtGui.QMainWindow = MainWindow, window_type: QtGui.QMainWindow = MainWindow,
) -> None: ) -> None:
# avoids annoying message when entering debugger from qt loop # avoids annoying message when entering debugger from qt loop
@ -90,26 +91,21 @@ def run_qtractor(
} }
# setup tractor entry point args # setup tractor entry point args
args = ( main = partial(
# async_fn tractor._main,
func, async_fn=func,
# args (always append widgets list) args=args + (widgets,),
args + (widgets,), arbiter_addr=(
# kwargs
kwargs,
# arbiter_addr
(
tractor._default_arbiter_host, tractor._default_arbiter_host,
tractor._default_arbiter_port, tractor._default_arbiter_port,
), ),
# name name='qtractor',
'qtractor', **tractor_kwargs,
) )
# guest mode # guest mode
trio.lowlevel.start_guest_run( trio.lowlevel.start_guest_run(
tractor._main, main,
*args,
run_sync_soon_threadsafe=run_sync_soon_threadsafe, run_sync_soon_threadsafe=run_sync_soon_threadsafe,
done_callback=done_callback, done_callback=done_callback,
) )

View File

@ -63,6 +63,7 @@ def monitor(config, rate, name, dhost, test, tl):
name='monitor', name='monitor',
loglevel=loglevel if tl else None, loglevel=loglevel if tl else None,
rpc_module_paths=['piker.ui.kivy.monitor'], rpc_module_paths=['piker.ui.kivy.monitor'],
debug_mode=True,
) )
@ -118,4 +119,11 @@ def chart(config, symbol, date, rate, test):
brokername = config['broker'] brokername = config['broker']
tractorloglevel = config['tractorloglevel'] tractorloglevel = config['tractorloglevel']
_main(sym=symbol, brokername=brokername, loglevel=tractorloglevel) _main(
sym=symbol,
brokername=brokername,
tractor_kwargs={
'debug_mode': True,
'loglevel': tractorloglevel,
},
)