Skip to content

Commit

Permalink
🎉 Interrupts execution on error (#265)
Browse files Browse the repository at this point in the history
  • Loading branch information
MathisFederico authored Feb 13, 2022
2 parents 9fa816d + 0b3d33a commit d12f55f
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
4 changes: 4 additions & 0 deletions pyflow/blocks/executableblock.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions pyflow/core/kernel.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
4 changes: 3 additions & 1 deletion pyflow/core/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -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()
Expand Down

0 comments on commit d12f55f

Please sign in to comment.