mirror of https://github.com/m-labs/artiq.git
applets: fix asyncio loop management
This commit is contained in:
parent
2f289c552f
commit
5f77d4f5fa
|
@ -49,7 +49,7 @@ def get_argparser():
|
||||||
|
|
||||||
class Browser(QtWidgets.QMainWindow):
|
class Browser(QtWidgets.QMainWindow):
|
||||||
def __init__(self, smgr, datasets_sub, browse_root,
|
def __init__(self, smgr, datasets_sub, browse_root,
|
||||||
master_host, master_port):
|
master_host, master_port, *, loop=None):
|
||||||
QtWidgets.QMainWindow.__init__(self)
|
QtWidgets.QMainWindow.__init__(self)
|
||||||
smgr.register(self)
|
smgr.register(self)
|
||||||
|
|
||||||
|
@ -81,7 +81,7 @@ class Browser(QtWidgets.QMainWindow):
|
||||||
self.files.dataset_changed.connect(
|
self.files.dataset_changed.connect(
|
||||||
self.experiments.dataset_changed)
|
self.experiments.dataset_changed)
|
||||||
|
|
||||||
self.applets = applets.AppletsDock(self, datasets_sub)
|
self.applets = applets.AppletsDock(self, datasets_sub, loop=loop)
|
||||||
smgr.register(self.applets)
|
smgr.register(self.applets)
|
||||||
atexit_register_coroutine(self.applets.stop, loop=loop)
|
atexit_register_coroutine(self.applets.stop, loop=loop)
|
||||||
|
|
||||||
|
@ -152,7 +152,7 @@ def main():
|
||||||
smgr = state.StateManager(args.db_file)
|
smgr = state.StateManager(args.db_file)
|
||||||
|
|
||||||
browser = Browser(smgr, datasets_sub, args.browse_root,
|
browser = Browser(smgr, datasets_sub, args.browse_root,
|
||||||
args.server, args.port)
|
args.server, args.port, loop=loop)
|
||||||
widget_log_handler.callback = browser.log.model.append
|
widget_log_handler.callback = browser.log.model.append
|
||||||
|
|
||||||
if os.name == "nt":
|
if os.name == "nt":
|
||||||
|
|
|
@ -195,7 +195,8 @@ def main():
|
||||||
"server": args.server,
|
"server": args.server,
|
||||||
"port_notify": args.port_notify,
|
"port_notify": args.port_notify,
|
||||||
"port_control": args.port_control,
|
"port_control": args.port_control,
|
||||||
})
|
},
|
||||||
|
loop=loop)
|
||||||
atexit_register_coroutine(d_applets.stop, loop=loop)
|
atexit_register_coroutine(d_applets.stop, loop=loop)
|
||||||
smgr.register(d_applets)
|
smgr.register(d_applets)
|
||||||
broadcast_clients["ccb"].notify_cbs.append(d_applets.ccb_notify)
|
broadcast_clients["ccb"].notify_cbs.append(d_applets.ccb_notify)
|
||||||
|
|
|
@ -92,9 +92,9 @@ class AppletIPCServer(AsyncioParentComm):
|
||||||
finally:
|
finally:
|
||||||
self.datasets_sub.notify_cbs.remove(self._on_mod)
|
self.datasets_sub.notify_cbs.remove(self._on_mod)
|
||||||
|
|
||||||
def start_server(self, embed_cb, fix_initial_size_cb):
|
def start_server(self, embed_cb, fix_initial_size_cb, *, loop=None):
|
||||||
self.server_task = asyncio.ensure_future(
|
self.server_task = asyncio.ensure_future(
|
||||||
self.serve(embed_cb, fix_initial_size_cb))
|
self.serve(embed_cb, fix_initial_size_cb), loop=loop)
|
||||||
|
|
||||||
async def stop_server(self):
|
async def stop_server(self):
|
||||||
if hasattr(self, "server_task"):
|
if hasattr(self, "server_task"):
|
||||||
|
@ -327,7 +327,7 @@ class _CompleterDelegate(QtWidgets.QStyledItemDelegate):
|
||||||
|
|
||||||
|
|
||||||
class AppletsDock(QtWidgets.QDockWidget):
|
class AppletsDock(QtWidgets.QDockWidget):
|
||||||
def __init__(self, main_window, datasets_sub, extra_substitutes={}):
|
def __init__(self, main_window, datasets_sub, extra_substitutes={}, *, loop=None):
|
||||||
"""
|
"""
|
||||||
:param extra_substitutes: Map of extra ``${strings}`` to substitute in applet
|
:param extra_substitutes: Map of extra ``${strings}`` to substitute in applet
|
||||||
commands to their respective values.
|
commands to their respective values.
|
||||||
|
@ -342,6 +342,8 @@ class AppletsDock(QtWidgets.QDockWidget):
|
||||||
self.extra_substitutes = extra_substitutes
|
self.extra_substitutes = extra_substitutes
|
||||||
self.applet_uids = set()
|
self.applet_uids = set()
|
||||||
|
|
||||||
|
self._loop = loop
|
||||||
|
|
||||||
self.table = QtWidgets.QTreeWidget()
|
self.table = QtWidgets.QTreeWidget()
|
||||||
self.table.setColumnCount(2)
|
self.table.setColumnCount(2)
|
||||||
self.table.setHeaderLabels(["Name", "Command"])
|
self.table.setHeaderLabels(["Name", "Command"])
|
||||||
|
@ -441,7 +443,7 @@ class AppletsDock(QtWidgets.QDockWidget):
|
||||||
dock = _AppletDock(self.datasets_sub, item.applet_uid, name, spec, self.extra_substitutes)
|
dock = _AppletDock(self.datasets_sub, item.applet_uid, name, spec, self.extra_substitutes)
|
||||||
self.main_window.addDockWidget(QtCore.Qt.RightDockWidgetArea, dock)
|
self.main_window.addDockWidget(QtCore.Qt.RightDockWidgetArea, dock)
|
||||||
dock.setFloating(True)
|
dock.setFloating(True)
|
||||||
asyncio.ensure_future(dock.start())
|
asyncio.ensure_future(dock.start(), loop=self._loop)
|
||||||
dock.sigClosed.connect(partial(self.on_dock_closed, item, dock))
|
dock.sigClosed.connect(partial(self.on_dock_closed, item, dock))
|
||||||
return dock
|
return dock
|
||||||
|
|
||||||
|
@ -480,7 +482,7 @@ class AppletsDock(QtWidgets.QDockWidget):
|
||||||
|
|
||||||
def on_dock_closed(self, item, dock):
|
def on_dock_closed(self, item, dock):
|
||||||
item.applet_geometry = dock.saveGeometry()
|
item.applet_geometry = dock.saveGeometry()
|
||||||
asyncio.ensure_future(dock.terminate())
|
asyncio.ensure_future(dock.terminate(), loop=self._loop)
|
||||||
item.setCheckState(0, QtCore.Qt.Unchecked)
|
item.setCheckState(0, QtCore.Qt.Unchecked)
|
||||||
|
|
||||||
def get_untitled(self):
|
def get_untitled(self):
|
||||||
|
@ -569,7 +571,7 @@ class AppletsDock(QtWidgets.QDockWidget):
|
||||||
if wi.ty == "applet":
|
if wi.ty == "applet":
|
||||||
dock = wi.applet_dock
|
dock = wi.applet_dock
|
||||||
if dock is not None:
|
if dock is not None:
|
||||||
asyncio.ensure_future(dock.restart())
|
asyncio.ensure_future(dock.restart(), loop=self._loop)
|
||||||
elif wi.ty == "group":
|
elif wi.ty == "group":
|
||||||
for i in range(wi.childCount()):
|
for i in range(wi.childCount()):
|
||||||
walk(wi.child(i))
|
walk(wi.child(i))
|
||||||
|
|
Loading…
Reference in New Issue