#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ @desc: @author: DYL @contact: [email protected] @site: www.xxxx.com @software: PyCharm @since:python 3.5.2 on 2016/11/3.10:49 """ from snow import Snow from snow import HttpResponse #http://www.cnblogs.com/wupeiqi/articles/6536518.html def index(request): return HttpResponse('OK') routes = [ (r'/index/', index), ] app = Snow(routes) app.run(port=8012)
def req(request): obj = Future( callback=callback ) # <snow.Future object at 0x000001535D47D278> HttpResponse(future.value) request_list.append(obj) print('request_list', request_list) yield obj #yield 是一个类似 return 的关键字,只是这个函数返回的是个生成器,返回的生成器调用成员方法时,相应的生成器函数中的代码才会执行 def stop(request): obj = request_list[0] #列表一直增加,这个就取第一个 del request_list[0] #然后删除掉 obj.set_result('done') return HttpResponse('Stop') def callback(request, future): return HttpResponse(future.value) routes = [ # ('/index/',index), ('/async/', async), #超时 ('/req/', req), #自己停止 ('/stop/', stop), ] app = Snow(routes) app.run(port=8001)