[Python] How to call helper functions from task.external_python in dag without set sys.path...

Discussão em 'Python' iniciado por Stack, Fevereiro 12, 2025.

  1. Stack

    Stack Membro Participativo

    I have a helper function need to run in every task to init environment.

    The problem is, task can not access any variable out of it self's scope. So I have to add the same code to the beginning of every task, like:

    @task.external_python(
    python=v_python_path,
    retries=3,
    )
    def init_env():
    ### this part have to be added for every task
    import sys

    sys.path.append("/opt/airflow/dags")
    ####

    from my_module import my_function


    Is there a way to make it cleaner and graceful?

    Continue reading...

Compartilhe esta Página