【发布时间】:2016-10-26 00:55:04
【问题描述】:
我有以下课程:
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不返回可调用对象。切换装饰器,以便首先调用gen.coroutine。 -
请包含调用此函数的代码。
-
@jonrsharpe
@classmethod返回什么以及如何使它成为一个协程? -
@freeza 它返回
<classmethod object at 0x...>和TypeError: 'classmethod' object is not callable。您需要重新订购您的装饰器。 -
@advance512 请注意,在这种情况下并不重要,因为错误是在类定义时抛出的。