|
7 | 7 | import typing as t |
8 | 8 | from typing import List |
9 | 9 |
|
10 | | -from aiida.engine.processes.functions import FunctionType, get_stack_size |
| 10 | +from packaging.version import parse as parse_version |
| 11 | + |
| 12 | +import aiida |
| 13 | +from aiida.engine.processes.functions import FunctionType |
11 | 14 | from aiida.manage import get_manager |
12 | 15 | from aiida.orm import ProcessNode |
| 16 | + |
| 17 | +_AIIDA_VERSION = parse_version(aiida.__version__) |
| 18 | +_NEEDS_RECURSION_LIMIT_WORKAROUND = _AIIDA_VERSION < parse_version("2.8.0") |
| 19 | + |
| 20 | +if _NEEDS_RECURSION_LIMIT_WORKAROUND: |
| 21 | + from aiida.engine.processes.functions import get_stack_size |
13 | 22 | from node_graph.socket_spec import SocketSpec |
14 | 23 |
|
15 | 24 | from aiida_pythonjob.calculations.pyfunction import PyFunction |
@@ -42,25 +51,26 @@ def run_get_node(*args, **kwargs) -> tuple[dict[str, t.Any] | None, "ProcessNode |
42 | 51 | :param kwargs: input keyword arguments to construct the FunctionProcess |
43 | 52 | :return: tuple of the outputs of the process and the process node |
44 | 53 | """ |
45 | | - frame_delta = 1000 |
46 | | - frame_count = get_stack_size() |
47 | | - stack_limit = sys.getrecursionlimit() |
48 | | - LOGGER.info("Executing process function, current stack status: %d frames of %d", frame_count, stack_limit) |
49 | | - |
50 | | - # If the current frame count is more than 80% of the stack limit, or comes within 200 frames, increase the |
51 | | - # stack limit by ``frame_delta``. |
52 | | - if frame_count > min(0.8 * stack_limit, stack_limit - 200): |
53 | | - LOGGER.warning( |
54 | | - "Current stack contains %d frames which is close to the limit of %d. Increasing the limit by %d", |
55 | | - frame_count, |
56 | | - stack_limit, |
57 | | - frame_delta, |
| 54 | + if _NEEDS_RECURSION_LIMIT_WORKAROUND: |
| 55 | + frame_delta = 1000 |
| 56 | + frame_count = get_stack_size() |
| 57 | + stack_limit = sys.getrecursionlimit() |
| 58 | + LOGGER.info( |
| 59 | + "Executing process function, current stack status: %d frames of %d", frame_count, stack_limit |
58 | 60 | ) |
59 | | - sys.setrecursionlimit(stack_limit + frame_delta) |
| 61 | + |
| 62 | + if frame_count > min(0.8 * stack_limit, stack_limit - 200): |
| 63 | + LOGGER.warning( |
| 64 | + "Current stack contains %d frames which is close to the limit of %d. Increasing the limit by %d", |
| 65 | + frame_count, |
| 66 | + stack_limit, |
| 67 | + frame_delta, |
| 68 | + ) |
| 69 | + sys.setrecursionlimit(stack_limit + frame_delta) |
60 | 70 |
|
61 | 71 | manager = get_manager() |
62 | 72 | runner = manager.get_runner() |
63 | | - # # Remove all the known inputs from the kwargs |
| 73 | + # Remove all the known inputs from the kwargs |
64 | 74 | outputs_spec = kwargs.pop("outputs_spec", None) or outputs |
65 | 75 | inputs_spec = kwargs.pop("inputs_spec", None) or inputs |
66 | 76 | metadata = kwargs.pop("metadata", None) |
|
0 commit comments