Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🎉 Interrupts execution on error #265

Merged
merged 1 commit into from
Feb 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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