我只是通过追踪随机错误了,而使用扭曲:生成器装饰器是否存在?
@defer.inlineCallbacks
def myfunc():
# Function implementation with no yield statement.
而当myfunc
叫,我会得到先前追溯印刷但是:
Traceback (most recent call last):
File "/usr/lib/python2.7/dist-packages/twisted/spread/pb.py", line 826, in proto_message
self._recvMessage(self.localObjectForID, requestID, objectID, message, answerRequired, netArgs, netKw)
File "/usr/lib/python2.7/dist-packages/twisted/spread/pb.py", line 840, in _recvMessage
netResult = object.remoteMessageReceived(self, message, netArgs, netKw)
File "/usr/lib/python2.7/dist-packages/twisted/spread/flavors.py", line 114, in remoteMessageReceived
state = method(*args, **kw)
File "/usr/lib/python2.7/dist-packages/twisted/internet/defer.py", line 1141, in unwindGenerator
return _inlineCallbacks(None, f(*args, **kwargs), Deferred())
--- <exception caught here> ---
File "/usr/lib/python2.7/dist-packages/twisted/internet/defer.py", line 1020, in _inlineCallbacks
result = g.send(result)
exceptions.AttributeError: 'NoneType' object has no attribute 'send'
这是由引起该功能内的所有功能都正常工作这是因为它在调用时返回None
而不是发电机,期望返回defer.inlineCallbacks
。有没有方法来声明一个函数的生成器,而不是在函数体内放置一个yield语句?比如生成器装饰器?
“有没有办法在函数体中声明一个函数而不放置yield语句?”不会。这会如何解决你的问题? –
如果你的函数不是一个生成器(没有'yield'),那么使用'@ defer.inlineCallbacks'就没有意义了。你想做什么? –
Jochen Ritzel:我期待我会在函数中使用yield语句,所以我用'inlineCallbacks'对它进行了修饰,因为一些相似的函数确实包含了yield,但是chanse从来没有在这个特定的函数中使用yield。 – cpburnz