mirror of
https://github.com/m-labs/artiq.git
synced 2024-12-25 11:18:27 +08:00
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):
|
||||
def __init__(self, smgr, datasets_sub, browse_root,
|
||||
master_host, master_port):
|
||||
master_host, master_port, *, loop=None):
|
||||
QtWidgets.QMainWindow.__init__(self)
|
||||
smgr.register(self)
|
||||
|
||||
@ -81,7 +81,7 @@ class Browser(QtWidgets.QMainWindow):
|
||||
self.files.dataset_changed.connect(
|
||||
self.experiments.dataset_changed)
|
||||
|
||||
self.applets = applets.AppletsDock(self, datasets_sub)
|
||||
self.applets = applets.AppletsDock(self, datasets_sub, loop=loop)
|
||||
smgr.register(self.applets)
|
||||
atexit_register_coroutine(self.applets.stop, loop=loop)
|
||||
|
||||
@ -152,7 +152,7 @@ def main():
|
||||
smgr = state.StateManager(args.db_file)
|
||||
|
||||
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
|
||||
|
||||
if os.name == "nt":
|
||||
|
@ -195,7 +195,8 @@ def main():
|
||||
"server": args.server,
|
||||
"port_notify": args.port_notify,
|
||||
"port_control": args.port_control,
|
||||
})
|
||||
},
|
||||
loop=loop)
|
||||
atexit_register_coroutine(d_applets.stop, loop=loop)
|
||||
smgr.register(d_applets)
|
||||
broadcast_clients["ccb"].notify_cbs.append(d_applets.ccb_notify)
|
||||
|
@ -92,9 +92,9 @@ class AppletIPCServer(AsyncioParentComm):
|
||||
finally:
|
||||
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.serve(embed_cb, fix_initial_size_cb))
|
||||
self.serve(embed_cb, fix_initial_size_cb), loop=loop)
|
||||
|
||||
async def stop_server(self):
|
||||
if hasattr(self, "server_task"):
|
||||
@ -327,7 +327,7 @@ class _CompleterDelegate(QtWidgets.QStyledItemDelegate):
|
||||
|
||||
|
||||
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
|
||||
commands to their respective values.
|
||||
@ -342,6 +342,8 @@ class AppletsDock(QtWidgets.QDockWidget):
|
||||
self.extra_substitutes = extra_substitutes
|
||||
self.applet_uids = set()
|
||||
|
||||
self._loop = loop
|
||||
|
||||
self.table = QtWidgets.QTreeWidget()
|
||||
self.table.setColumnCount(2)
|
||||
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)
|
||||
self.main_window.addDockWidget(QtCore.Qt.RightDockWidgetArea, dock)
|
||||
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))
|
||||
return dock
|
||||
|
||||
@ -480,7 +482,7 @@ class AppletsDock(QtWidgets.QDockWidget):
|
||||
|
||||
def on_dock_closed(self, item, dock):
|
||||
item.applet_geometry = dock.saveGeometry()
|
||||
asyncio.ensure_future(dock.terminate())
|
||||
asyncio.ensure_future(dock.terminate(), loop=self._loop)
|
||||
item.setCheckState(0, QtCore.Qt.Unchecked)
|
||||
|
||||
def get_untitled(self):
|
||||
@ -569,7 +571,7 @@ class AppletsDock(QtWidgets.QDockWidget):
|
||||
if wi.ty == "applet":
|
||||
dock = wi.applet_dock
|
||||
if dock is not None:
|
||||
asyncio.ensure_future(dock.restart())
|
||||
asyncio.ensure_future(dock.restart(), loop=self._loop)
|
||||
elif wi.ty == "group":
|
||||
for i in range(wi.childCount()):
|
||||
walk(wi.child(i))
|
||||
|
Loading…
Reference in New Issue
Block a user