python - 使用 ReturnValue 时出现扭曲异常

标签 python twisted

在函数中使用返回值时出现此异常

@inlineCallbacks    
def my_func(id):
  yield somefunc(id)

@inlineCallbacks
def somefunc(id):
  somevar = yield func(id) 
  returnValue(somevar)



returnValue(somevar)
File "/usr/lib64/python2.7/site-packages/twisted/internet/defer.py", line 1105, in returnValue
raise _DefGen_Return(val)
twisted.internet.defer._DefGen_Return:

该函数工作正常,但引发异常。 我怎样才能避免这个异常?我只需要从函数返回一些值。

最佳答案

当使用inlineCallbacks时,你必须产生一个延迟 - 在这种情况下,my_func中的yield正在产生func(id) (我认为这是一个延迟),但随后调用了 returnValue 这是不允许的。

你可能可以这样做:

@inlineCallbacks    
def my_func(id):
   somevar = yield somefunc(id)

@inlineCallbacks
def somefunc(id):
    yield func(id) 

关于python - 使用 ReturnValue 时出现扭曲异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32200565/

相关文章:

python - 使用 sqlalchemy 和 postgres 的 SSL 系统调用错误文件描述符错误

python - 更改 "locale preferred encoding"

python - 在centos 6.x 上使用python3 安装twis​​ted 失败?

python - 在单独的线程中扭曲传输。

python - 找到 reCAPTCHA 元素并单击它 - Python + Selenium

python - 这个简单的正则表达式有什么问题?

python - Python 的 Twisted Reactor 是如何工作的?

python - 转换为 Twisted 异步设计

python - 如何避免扭曲的 tac 文件中出现导入错误?

python - 类型错误 : unhashable type: 'slice' for pandas