python runner是什么_Python gen.Runner方法代码示例

# 需要导入模块: from tornado import gen [as 别名]

# 或者: from tornado.gen import Runner [as 别名]

def test_yield_in_with(self):

@gen.engine

def f():

try:

self.callback = yield gen.Callback('a')

with StackContext(functools.partial(self.context, 'c1')):

# This yield is a problem: the generator will be suspended

# and the StackContext's __exit__ is not called yet, so

# the context will be left on _state.contexts for anything

# that runs before the yield resolves.

yield gen.Wait('a')

except StackContextInconsistentError:

# In python <= 3.3, this suspended generator is never garbage

# collected, so it remains suspended in the 'yield' forever.

# Starting in 3.4, it is made collectable by raising

# a GeneratorExit exception from the yield, which gets

# converted into a StackContextInconsistentError by the

# exit of the 'with' block.

pass

with self.assertRaises(StackContextInconsistentError):

f()

self.wait()

# Cleanup: to avoid GC warnings (which for some reason only seem

# to show up on py33-asyncio), invoke the callback (which will do

# nothing since the gen.Runner is already finished) and delete it.

self.callback()

del self.callback

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值