diff --git a/airflow-core/newsfragments/70280.bugfix.rst b/airflow-core/newsfragments/70280.bugfix.rst new file mode 100644 index 0000000000000..f6f8d8382c8bc --- /dev/null +++ b/airflow-core/newsfragments/70280.bugfix.rst @@ -0,0 +1 @@ +Restored support for ``[core] execute_tasks_new_python_interpreter`` when running tasks with LocalExecutor and CeleryExecutor. diff --git a/task-sdk/src/airflow/sdk/execution_time/supervisor.py b/task-sdk/src/airflow/sdk/execution_time/supervisor.py index 87311f02da7a1..27133bc6d4905 100644 --- a/task-sdk/src/airflow/sdk/execution_time/supervisor.py +++ b/task-sdk/src/airflow/sdk/execution_time/supervisor.py @@ -515,8 +515,10 @@ def exit(n: int) -> NoReturn: def _should_use_exec() -> bool: - """Whether forked children should ``exec`` a fresh interpreter on this platform.""" - return sys.platform in _FORK_EXEC_PLATFORMS + """Whether forked children should ``exec`` a fresh interpreter.""" + return sys.platform in _FORK_EXEC_PLATFORMS or conf.getboolean( + "core", "execute_tasks_new_python_interpreter", fallback=False + ) def _resolve_child_target(dotted: str) -> Callable[[], None]: diff --git a/task-sdk/tests/task_sdk/execution_time/test_supervisor.py b/task-sdk/tests/task_sdk/execution_time/test_supervisor.py index 7ba463567a17a..9bf7c2428f6b9 100644 --- a/task-sdk/tests/task_sdk/execution_time/test_supervisor.py +++ b/task-sdk/tests/task_sdk/execution_time/test_supervisor.py @@ -185,6 +185,17 @@ TI_ID = uuid7() +@pytest.mark.parametrize( + ("platform", "config_value", "expected"), + [("darwin", False, True), ("linux", True, True), ("linux", False, False)], +) +def test_should_use_exec_honors_platform_and_config(monkeypatch, platform, config_value, expected): + monkeypatch.setattr(supervisor.sys, "platform", platform) + monkeypatch.setattr(supervisor.conf, "getboolean", lambda *args, **kwargs: config_value) + + assert supervisor._should_use_exec() is expected + + def lineno(): """Returns the current line number in our program.""" return inspect.currentframe().f_back.f_lineno