我有以下课程:
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 aggrTypeError: types.coroutine()需要一个可调用的
你能告诉我问题出在哪里吗?
调用此函数的=>编辑代码
print(DemoVertex.find_by_value('longitude', 55.0))发布于 2016-06-23 15:44:35
问题是classmethod .有趣的事。类定义完成后,类上有一个很好的可调用方法,但是在定义过程中,您有一个classmethod object,它是不可调用的:
>>> 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最简单的解决方法是重新排序装饰器,这样就不会试图将类方法转换为协同线:
@gen.coroutine
@classmethod
def thing(...):
...您正在尝试将协同线转换为类方法:
@classmethod
@gen.coroutine
def thing(...):
...请注意,装饰器是“内向外”应用的,参见Decorator execution order。
https://stackoverflow.com/questions/37995862
复制相似问题