Add `execute_tasks_new_python_interpreter` argument to `PythonOperator`
Description
Currently from my knowledge it is only possible to force all python tasks to execute in a new interpreter for every execution globally via this setting:
- https://airflow.apache.org/docs/apache-airflow/stable/configurations-ref.html#execute-tasks-new-python-interpreter
Would it be possible to add this argument to the PythonOperator so it is possible to control this behavior at the task level?
Use case/motivation
- https://github.com/apache/airflow/discussions/40956
Related issues
- https://github.com/apache/airflow/discussions/40956
Are you willing to submit a PR?
- [ ] Yes I am willing to submit a PR!
Code of Conduct
- [X] I agree to follow this project's Code of Conduct
Marked it as a good first issue for anyone to take - but feel free to propose a PR as well.
Hi @potiuk, I would like to work on this issue as my first issue. May I ?
Sure
@potiuk I have updated description of PR and answer your que. I think it would solve your query.
@Prab-27 We are unassigning you from this issue as part of our updated assignment policy.
This is not meant to discourage your contribution — quite the opposite! You are still very welcome to work on this issue and submit a PR for it. Simply comment that you are working on it and open a PR when ready.
We found that formal assignments were not working well, as they often prevented others from contributing when the assignee was not actively working on the issue.
Hi, I'd like to work on this. Looking at the current code, the exec decision is made in the task supervisor (task_process_uses_exec() in task-sdk/src/airflow/sdk/execution_time/supervisor.py), which today only reads the global [core] execute_tasks_new_python_interpreter config. My proposed approach:
- Add an
execute_tasks_new_python_interpreter: bool | None = Noneargument toPythonOperator(None = fall back to the global config). - Carry the value to the supervisor alongside the other per-task execution context (similar to how retry-related context is passed), so
task_process_uses_exec()can prefer the per-task value when set. - Keep the platform gate (macOS) forcing exec regardless.
Before I write code, could a maintainer confirm whether the per-task value should travel via the TI context from the API server, or whether there's a preferred existing channel for per-task execution flags? Happy to adjust the design.