带a的Python运算符。返回类型

带a的Python运算符。返回类型,python,airflow,Python,Airflow,我的DAG中有一个python操作符。python可调用函数正在返回bool值。但是,当我运行DAG时,我得到以下错误 TypeError:“bool”对象不可调用 我修改了函数,使其不返回任何内容,但再次出现以下错误 错误-“非类型”对象不可调用 下面是我的dag def check_poke(threshold,sleep_interval): flag=snowflake_poke(1000,10).poke() #print(flag) return flag dependency =

我的DAG中有一个python操作符。python可调用函数正在返回bool值。但是,当我运行DAG时,我得到以下错误

TypeError:“bool”对象不可调用

我修改了函数,使其不返回任何内容,但再次出现以下错误

错误-“非类型”对象不可调用

下面是我的dag

def check_poke(threshold,sleep_interval):
flag=snowflake_poke(1000,10).poke()
#print(flag)
return flag

dependency = PythonOperator(
task_id='poke_check',
#python_callable=check_poke(129600,600),
provide_context=True,
python_callable=check_poke(129600,600),
dag=dag)

end = BatchEndOperator(
queue=QUEUE,
dag=dag)

start.set_downstream(dependency)
dependency.set_downstream(end)
不知道我错过了什么。有人能帮我解决这个问题吗…对气流来说是个新手

我在dag中编辑了python操作符,如下所示

dependency = PythonOperator(
task_id='poke_check',
provide_context=True,
python_callable=check_poke(129600,600),
dag=dag)
但是现在,我得到了一个不同的错误

Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/airflow/models.py", line 1245, in run
    result = task_copy.execute(context=context)
File "/usr/local/lib/python2.7/dist-packages/airflow/operators/python_operator.py", line 66, in execute
    return_value = self.python_callable(*self.op_args, **self.op_kwargs)
TypeError: () takes no arguments (25 given)
[2019-02-15 05:30:25,375] {models.py:1298} INFO - Marking task as UP_FOR_RETRY
[2019-02-15 05:30:25,393] {models.py:1327} ERROR - () takes no arguments (25 given)

参数名给出了它。您正在传递调用的结果,而不是可调用的结果

python_callable=check_poke(129600,600)
第二个错误表示调用该可调用函数时使用了25个参数。所以一个
lambda:
将不起作用。以下方法可行,但忽略25个参数确实值得怀疑

python_callable=lambda *args, **kwargs: check_poke(129600,600)

同意Dan D.关于该问题的意见;但令人困惑的是,为什么他的解决方案不起作用(它在
python
shell中确实起作用)

看看这是否给你带来了好运(这只是Dan D.解决方案的冗长变体)

输入import Callable
#你原来的支票功能
def检查戳(arg_1:int,arg_2:int)->bool:
#做点什么
#以某种方式返回一个布尔
返回arg_1可调用[],bool]:
def check_poke_wrapper()->bool:
退回支票(arg_1=arg_1,arg_2=arg_2)
退换货支票
..
#用法
python\u callable=check\u poke\u wrapper\u creator(129600600)
显然这个问题演变成了
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)