Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/333.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-core/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 错误:types.coroutine()需要一个可调用的_Python_Tornado - Fatal编程技术网

Python 错误:types.coroutine()需要一个可调用的

Python 错误:types.coroutine()需要一个可调用的,python,tornado,Python,Tornado,我有以下课程: from tornado import gen class VertexSync(Vertex): @wait_till_complete @gen.coroutine @classmethod def find_by_value(cls, *args, **kwargs): stream = yield super().find_by_value(*args, **kwargs) aggr = []

我有以下课程:

from tornado import gen

class VertexSync(Vertex):
    @wait_till_complete
    @gen.coroutine
    @classmethod
    def find_by_value(cls, *args, **kwargs):
        stream = yield super().find_by_value(*args, **kwargs)
        aggr = []
        while True:
            resp = yield stream.read()
            if resp is None:
                break
            aggr = aggr + resp
        return aggr
TypeError:types.coroutine()需要一个可调用的

你能告诉我是什么问题吗

=>编辑 调用此函数的代码

print(DemoVertex.find_by_value('longitude', 55.0))

问题是
classmethod
不。。。有趣的事情。一旦类定义完成,您就有了一个很好的类调用方法,但是在定义过程中,您有一个
classmethod对象
,它是不可调用的:

>>> a = classmethod(lambda self: None)
>>> a
<classmethod object at 0x10b46b390>
>>> callable(a)
False
>>> a()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: 'classmethod' object is not callable
您正在尝试将协同程序转换为类方法:

@classmethod
@gen.coroutine
def thing(...):
    ...

请注意,装饰器是“由内而外”应用的,请参见,例如,

问题在于
classmethod
不。。。有趣的事情。一旦类定义完成,您就有了一个很好的类调用方法,但是在定义过程中,您有一个
classmethod对象
,它是不可调用的:

>>> a = classmethod(lambda self: None)
>>> a
<classmethod object at 0x10b46b390>
>>> callable(a)
False
>>> a()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: 'classmethod' object is not callable
您正在尝试将协同程序转换为类方法:

@classmethod
@gen.coroutine
def thing(...):
    ...

请注意,装饰符是“由内而外”应用的,请参见例如

@classmethod
不返回可调用的。切换装饰程序,以便首先调用
gen.coroutine
。请包含调用此函数的代码。@jornsharpe
@classmethod
返回什么以及如何使其成为corutine?@freeza it返回
,并且
类型错误:'classmethod'对象不可调用
。您需要重新排序装饰程序。@advance512请注意,在这种情况下这并不重要,因为错误是在类定义时抛出的。
@classmethod
不会返回可调用的。切换装饰程序,以便首先调用
gen.coroutine
。请包含调用此函数的代码。@jornsharpe
@classmethod
返回什么以及如何使其成为corutine?@freeza it返回
,并且
类型错误:'classmethod'对象不可调用
。您需要重新排序装饰程序。@advance512请注意,在这种情况下这并不重要,因为错误是在类定义时抛出的。