3 回答

TA貢獻1966條經(jīng)驗 獲得超4個贊
參數(shù)名稱給出了它。您正在傳遞調(diào)用的結(jié)果而不是可調(diào)用的。
python_callable=check_poke(129600,600)
第二個錯誤指出 callable 是用 25 個參數(shù)調(diào)用的。所以是lambda:
行不通的。以下方法可行,但忽略 25 個參數(shù)確實值得懷疑。
python_callable=lambda *args, **kwargs: check_poke(129600,600)

TA貢獻1821條經(jīng)驗 獲得超6個贊
代碼需要一個可調(diào)用的,而不是結(jié)果(正如已經(jīng)指出的那樣)。
您可以使用functools.Partial來填寫參數(shù):
from functools import partial
def check_poke(threshold,sleep_interval):
flag=snowflake_poke(1000,10).poke()
return flag
func = partial(check_poke, 129600, 600)
dependency = PythonOperator(
task_id='poke_check',
provide_context=True,
python_callable=func,
dag=dag)

TA貢獻1893條經(jīng)驗 獲得超10個贊
同意@Dan D.的問題;但令人困惑的是為什么他的解決方案不起作用(它在python shell 中肯定有效)
看看這是否會給您帶來任何運氣(它只是@Dan D.解決方案的詳細變體)
from typing import Callable
# your original check_poke function
def check_poke(arg_1: int, arg_2: int) -> bool:
# do something
# somehow returns a bool
return arg_1 < arg_2
# a function that returns a callable, that in turn invokes check_poke
# with the supplied params
def check_poke_wrapper_creator(arg_1: int, arg_2: int) -> Callable[[], bool]:
def check_poke_wrapper() -> bool:
return check_poke(arg_1=arg_1, arg_2=arg_2)
return check_poke_wrapper
..
# usage
python_callable=check_poke_wrapper_creator(129600, 600)
添加回答
舉報