From dc2c19f08f6238fa654953cbc6767df9fab61239 Mon Sep 17 00:00:00 2001 From: Sebastien Bourdeauducq Date: Tue, 29 Mar 2016 17:34:38 +0800 Subject: [PATCH] gui/schedule: support terminating all experiments in a pipeline. Closes #262 --- artiq/gui/schedule.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/artiq/gui/schedule.py b/artiq/gui/schedule.py index adb116cd4..b18963050 100644 --- a/artiq/gui/schedule.py +++ b/artiq/gui/schedule.py @@ -83,6 +83,10 @@ class ScheduleDock(QtWidgets.QDockWidget): delete_action.setShortcut("SHIFT+DELETE") delete_action.setShortcutContext(QtCore.Qt.WidgetShortcut) self.table.addAction(delete_action) + terminate_pipeline = QtWidgets.QAction( + "Gracefully terminate all in pipeline", self.table) + terminate_pipeline.triggered.connect(self.terminate_pipeline_clicked) + self.table.addAction(terminate_pipeline) self.table_model = Model(dict()) schedule_sub.add_setmodel_callback(self.set_model) @@ -120,6 +124,32 @@ class ScheduleDock(QtWidgets.QDockWidget): self.status_bar.showMessage(msg) asyncio.ensure_future(self.delete(rid, graceful)) + async def request_term_multiple(self, rids): + for rid in rids: + try: + await self.schedule_ctl.request_termination(rid) + except: + # May happen if the experiment has terminated by itself + # while we were terminating others. + logger.debug("failed to request termination of RID %d", + rid, exc_info=True) + + def terminate_pipeline_clicked(self): + idx = self.table.selectedIndexes() + if idx: + row = idx[0].row() + selected_rid = self.table_model.row_to_key[row] + pipeline = self.table_model.backing_store[selected_rid]["pipeline"] + self.status_bar.showMessage("Requesting termination of all " + "experiments in pipeline '{}'".format(pipeline)) + + rids = set() + for rid, info in self.table_model.backing_store.items(): + if info["pipeline"] == pipeline: + rids.add(rid) + asyncio.ensure_future(self.request_term_multiple(rids)) + + def save_state(self): return bytes(self.table.horizontalHeader().saveState())