From 0864506d4191d9ab5af15426c74cabb2701b2f67 Mon Sep 17 00:00:00 2001 From: Alexander Goscinski Date: Sun, 1 Mar 2026 20:14:11 +0100 Subject: [PATCH 1/3] Make the recursion limit workaround dependent on the aiida-core version (#72) With aiida-core v2.8.0 we switched from nest-asyncio to greenlet and therefore do not need to dynamically increase the recursion limit anymore. --- src/aiida_pythonjob/decorator.py | 41 +++++++++++++++++++------------- 1 file changed, 25 insertions(+), 16 deletions(-) diff --git a/src/aiida_pythonjob/decorator.py b/src/aiida_pythonjob/decorator.py index e89b573..1c788b4 100644 --- a/src/aiida_pythonjob/decorator.py +++ b/src/aiida_pythonjob/decorator.py @@ -7,16 +7,24 @@ import typing as t from typing import List -from aiida.engine.processes.functions import FunctionType, get_stack_size +import aiida +from aiida.engine.processes.functions import FunctionType from aiida.manage import get_manager from aiida.orm import ProcessNode from node_graph.socket_spec import SocketSpec +from packaging.version import parse as parse_version from aiida_pythonjob.calculations.pyfunction import PyFunction from aiida_pythonjob.launch import create_inputs, prepare_pyfunction_inputs LOGGER = logging.getLogger(__name__) +_AIIDA_VERSION = parse_version(aiida.__version__) +_NEEDS_RECURSION_LIMIT_WORKAROUND = _AIIDA_VERSION < parse_version("2.8.0") + +if _NEEDS_RECURSION_LIMIT_WORKAROUND: + from aiida.engine.processes.functions import get_stack_size + # The following code is modified from the aiida-core.engine.processes.functions module def pyfunction( @@ -42,25 +50,26 @@ def run_get_node(*args, **kwargs) -> tuple[dict[str, t.Any] | None, "ProcessNode :param kwargs: input keyword arguments to construct the FunctionProcess :return: tuple of the outputs of the process and the process node """ - frame_delta = 1000 - frame_count = get_stack_size() - stack_limit = sys.getrecursionlimit() - LOGGER.info("Executing process function, current stack status: %d frames of %d", frame_count, stack_limit) - - # If the current frame count is more than 80% of the stack limit, or comes within 200 frames, increase the - # stack limit by ``frame_delta``. - if frame_count > min(0.8 * stack_limit, stack_limit - 200): - LOGGER.warning( - "Current stack contains %d frames which is close to the limit of %d. Increasing the limit by %d", - frame_count, - stack_limit, - frame_delta, + if _NEEDS_RECURSION_LIMIT_WORKAROUND: + frame_delta = 1000 + frame_count = get_stack_size() + stack_limit = sys.getrecursionlimit() + LOGGER.info( + "Executing process function, current stack status: %d frames of %d", frame_count, stack_limit ) - sys.setrecursionlimit(stack_limit + frame_delta) + + if frame_count > min(0.8 * stack_limit, stack_limit - 200): + LOGGER.warning( + "Current stack contains %d frames which is close to the limit of %d. Increasing the limit by %d", + frame_count, + stack_limit, + frame_delta, + ) + sys.setrecursionlimit(stack_limit + frame_delta) manager = get_manager() runner = manager.get_runner() - # # Remove all the known inputs from the kwargs + # Remove all the known inputs from the kwargs outputs_spec = kwargs.pop("outputs_spec", None) or outputs inputs_spec = kwargs.pop("inputs_spec", None) or inputs metadata = kwargs.pop("metadata", None) From 01740543cd76b9497adb2332043acb5ab0ee80f3 Mon Sep 17 00:00:00 2001 From: Alexander Goscinski Date: Sun, 1 Mar 2026 20:52:22 +0100 Subject: [PATCH 2/3] Consider pre-release version when disabling recursion limit workaround (#73) The fix in 86f21bd4 only considered 2.8.0 and above, for any pre-release the workaround was not correctly disabled. --- src/aiida_pythonjob/decorator.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/aiida_pythonjob/decorator.py b/src/aiida_pythonjob/decorator.py index 1c788b4..98528fb 100644 --- a/src/aiida_pythonjob/decorator.py +++ b/src/aiida_pythonjob/decorator.py @@ -20,7 +20,7 @@ LOGGER = logging.getLogger(__name__) _AIIDA_VERSION = parse_version(aiida.__version__) -_NEEDS_RECURSION_LIMIT_WORKAROUND = _AIIDA_VERSION < parse_version("2.8.0") +_NEEDS_RECURSION_LIMIT_WORKAROUND = _AIIDA_VERSION < parse_version("2.8.0rc0") if _NEEDS_RECURSION_LIMIT_WORKAROUND: from aiida.engine.processes.functions import get_stack_size From f6579c9e4ae8f2e2002f2ee41a1cc1e9b8d21503 Mon Sep 17 00:00:00 2001 From: Alexander Goscinski Date: Tue, 3 Mar 2026 11:53:06 +0100 Subject: [PATCH 3/3] Release 0.4.9 --- src/aiida_pythonjob/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/aiida_pythonjob/__init__.py b/src/aiida_pythonjob/__init__.py index 6708707..4a3eed0 100644 --- a/src/aiida_pythonjob/__init__.py +++ b/src/aiida_pythonjob/__init__.py @@ -1,6 +1,6 @@ """AiiDA plugin that run Python function on remote computers.""" -__version__ = "0.4.8" +__version__ = "0.4.9" from node_graph import socket_spec as spec