From 0b3d33a19a4026650bf9224a2b51d69247423004 Mon Sep 17 00:00:00 2001 From: AlexandreSajus Date: Sun, 13 Feb 2022 16:25:47 +0100 Subject: [PATCH] :tada: interrupts execution on error --- pyflow/blocks/executableblock.py | 4 ++++ pyflow/core/kernel.py | 4 ++-- pyflow/core/worker.py | 4 +++- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/pyflow/blocks/executableblock.py b/pyflow/blocks/executableblock.py index c7ef34c1..7bea46b1 100644 --- a/pyflow/blocks/executableblock.py +++ b/pyflow/blocks/executableblock.py @@ -332,6 +332,10 @@ def reset_has_been_run(self): """Called when the output is an error.""" self.has_been_run = False + def error_occured(self): + """Interrupt the kernel if an error occured""" + self._interrupt_execution() + @property @abstractmethod def source(self) -> str: diff --git a/pyflow/core/kernel.py b/pyflow/core/kernel.py index 91a5f866..7f48a53b 100644 --- a/pyflow/core/kernel.py +++ b/pyflow/core/kernel.py @@ -72,14 +72,14 @@ def run_block(self, block, code: str): block: CodeBlock to send the output to code: String representing a piece of Python code to execute """ - worker = Worker(self, code) + worker = Worker(self, block, code) # Change color to running block.run_state = 1 worker.signals.stdout.connect(block.handle_stdout) worker.signals.image.connect(block.handle_image) worker.signals.finished.connect(self.run_queue) worker.signals.finished.connect(block.execution_finished) - worker.signals.error.connect(block.reset_has_been_run) + worker.signals.error.connect(block.error_occured) block.scene().threadpool.start(worker) def run_queue(self): diff --git a/pyflow/core/worker.py b/pyflow/core/worker.py index 60912843..61939871 100644 --- a/pyflow/core/worker.py +++ b/pyflow/core/worker.py @@ -20,11 +20,12 @@ class WorkerSignals(QObject): class Worker(QRunnable): """Worker thread.""" - def __init__(self, kernel, code): + def __init__(self, kernel, block, code): """Initialize the worker object.""" super().__init__() self.kernel = kernel + self.block = block self.code = code self.signals = WorkerSignals() @@ -43,6 +44,7 @@ async def run_code(self): elif output_type == "image": self.signals.image.emit(output) elif output_type == "error": + self.block.reset_has_been_run() self.signals.error.emit() self.signals.stdout.emit(output) self.signals.finished.emit()