我只是通過追蹤隨機錯誤了,而使用扭曲:生成器裝飾器是否存在?
@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