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请注意,在这种情况下这并不重要,因为错误是在类定义时抛出的。