def test(): yield 1
>>> test() <generator object test at 0x100b3b320>
>>> t = test() >>> t.next() 1
>>> def test(): a = yield print(a)
#!/usr/bin/env python # -*- coding:utf-8 -*-
from __future__ import absolute_import, print_function, division, with_statement
def loop1():
""" 循环1负责抛出一个函数和对应的参数, 并接收结果
"""
a = 0
ret = 1
while True:
ret = yield sum, [a, ret]
a, ret = ret, a
print("Loop1 ret", ret)
def loop2():
""" 循环2 负责接收函数并计算结果, 然后 yield 出结果
"""
while True:
func, args = yield
yield func(args)
print("Loop2")
l1 = loop1()
l2 = loop2()
tmp = l1.next()
for i in range(10):
l2.next()
ret = l2.send(tmp)
tmp = l1.send(ret)
#!/usr/bin/env python
# -*- coding:utf-8 -*-
from __future__ import absolute_import, print_function, division, with_statement
from tornado import gen
from tornado import web
from tornado import httpclient
class ActionHandler(web.RequestHandler):
@gen.coroutine
def get(self):
response = yield httpclient.AsyncHTTPClient().fetch("http://www.linuxzen.com")
# ...
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有