gpt4 book ai didi

python - BaseOperator.xcom_pull 中的上下文参数是什么

转载 作者:行者123 更新时间:2023-11-28 21:45:09 26 4
gpt4 key购买 nike

我正在阅读 API 文档,但不清楚 BaseOperator.xcom_pullcontext 参数是什么.

我以为是 dag.default_args,但我收到了 KeyError: 'ti'

我在 push() 示例之后的先前任务中执行了 xcom_push here .

最佳答案

上下文是一组关键字参数,包含与任务实例相关的引用对象,例如dagdag_runrun_idexecution_date等(包括任务实例ti本身)。

默认上下文在任务实例运行时生成,定义为here .

在您提到的示例中,传入上下文的方式不是很明显:如果 provide_context arg 设置为 True,Airflow 会将生成的上下文传递给 python 可调用对象。然后您可以访问任务实例的 xcom_pull通过调用 kwargs['ti'].xcom_pull() 方法。

这就是为什么要让它起作用,你需要在你的 python 可调用文件的 header 中定义 **kwargs,并将操作符的 provide_context arg 设置为 True

不过我不确定如何直接获取上下文引用。

关于python - BaseOperator.xcom_pull 中的上下文参数是什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39835068/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com