From 13c8ab42375528b2578597276dc474d6b63e027b Mon Sep 17 00:00:00 2001 From: liamhuber Date: Mon, 5 Jun 2023 11:59:37 -0700 Subject: [PATCH 1/3] Extract processing output So it can be registered as a callback --- pyiron_contrib/workflow/node.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/pyiron_contrib/workflow/node.py b/pyiron_contrib/workflow/node.py index e0d5cb99d..bd6b25265 100644 --- a/pyiron_contrib/workflow/node.py +++ b/pyiron_contrib/workflow/node.py @@ -485,6 +485,18 @@ def run(self) -> None: self.failed = True raise e + self.process_output(function_output) + + def process_output(self, function_output): + """ + Take the results of the node function, and use them to update the node. + + By extracting this as a separate method, we allow the node to pass the actual + execution off to another entity and release the python process to do other + things. In such a case, this function should be registered as a callback + so that the node can finishing "running" and push its data forward when that + execution is finished. + """ if len(self.outputs) == 1: function_output = (function_output,) From 22d6c9f3c19abc2f94933fe0a21f961fb7dd6e35 Mon Sep 17 00:00:00 2001 From: liamhuber Date: Mon, 5 Jun 2023 12:02:19 -0700 Subject: [PATCH 2/3] Pre-emptively add a server attribute We can settle on a name and exact behaviour later --- pyiron_contrib/workflow/node.py | 1 + 1 file changed, 1 insertion(+) diff --git a/pyiron_contrib/workflow/node.py b/pyiron_contrib/workflow/node.py index bd6b25265..a494c91d0 100644 --- a/pyiron_contrib/workflow/node.py +++ b/pyiron_contrib/workflow/node.py @@ -328,6 +328,7 @@ def __init__( self.running = False self.failed = False + self.server = None # Or "task_manager" or "executor" -- we'll see what's best self.node_function = node_function self.label = label if label is not None else node_function.__name__ From 2543756af6f335460c11f8a71ce74e9cf4e9b386 Mon Sep 17 00:00:00 2001 From: liamhuber Date: Mon, 5 Jun 2023 12:04:53 -0700 Subject: [PATCH 3/3] Wrap execution in a server check --- pyiron_contrib/workflow/node.py | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/pyiron_contrib/workflow/node.py b/pyiron_contrib/workflow/node.py index a494c91d0..e0fb93c54 100644 --- a/pyiron_contrib/workflow/node.py +++ b/pyiron_contrib/workflow/node.py @@ -479,14 +479,20 @@ def run(self) -> None: self.running = True self.failed = False - try: - function_output = self.node_function(**self.inputs.to_value_dict()) - except Exception as e: - self.running = False - self.failed = True - raise e - - self.process_output(function_output) + if self.server is None: + try: + function_output = self.node_function(**self.inputs.to_value_dict()) + except Exception as e: + self.running = False + self.failed = True + raise e + self.process_output(function_output) + else: + raise NotImplementedError( + "We currently only support executing the node functionality right on " + "the main python process that the node instance lives on. Come back " + "later for cool new features." + ) def process_output(self, function_output): """