基于Python的Web框架FastPy 2.1版发布

[复制链接]
查看11 | 回复1 | 2014-2-19 11:55:14 | 显示全部楼层 |阅读模式
FastPy 2.1 发布,此版本主要增加:
1、异步返回接口 request.ret(content)
2、增加单例调用示例,具体可参考例子 example.py
C++版本服务器框架亦有更新 具体可参考 fastrpc

回复

使用道具 举报

千问 | 2014-2-19 11:55:14 | 显示全部楼层
#-*- coding:utf-8 -*-
import os
import sys
import time
import thread

class Singleton(object):
def __new__(cls, *args, **kw):
if not hasattr(cls, '_instance'):

orig = super(Singleton, cls)

cls._instance = orig.__new__(cls, *args, **kw)

try:

method = getattr(cls._instance, "single_init")

method()

except Exception,e:

print "single_init is null"
return cls._instance

def done(request, response_head, res):
time.sleep(1)
res += "second"
request.ret(res)

class example(Singleton):

def single_init(self):
self.a = 1
print "init"

def test_alive(self, request, response_head):
return str(self.a)
res = "first "
thread.start_new_thread(done, (request, response_head, res))复制代码
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行