Skip to content

Instantly share code, notes, and snippets.

@shihongzhi
Created May 26, 2012 03:00
Show Gist options
  • Save shihongzhi/2791877 to your computer and use it in GitHub Desktop.
Save shihongzhi/2791877 to your computer and use it in GitHub Desktop.
一道面试题,具体见我的博客http://shihongzhi.github.com/。这里使用bjoern作为WSGI server,从reqeust的‘QUERY_STRING’中得到json数据。这里的stategys和actions变量保存了需要处理的策略和行为。limit_time为限制次数。 本程序有个问题,当数据特别大的时候,datas这个list会特别大,导致性能下降,可以考虑用队列替换list,定时删除那些过时的json数据
# --- coding:utf-8 ---
import strategy
import bjoern
from urlparse import parse_qsl
strategys = [strategy.strategy_highfreq, strategy.strategy_repetition]
actions = ['answer', 'comment', 'question']
limit_time = 10
datas = []
def wsgi_app(env, start_response):
start_response('200 ok', [])
data = dict(parse_qsl(env.get('QUERY_STRING', ''))) #string to dict
datas.append(data)
for s in strategys:
for action in actions:
s(action, datas, limit_time)
return ['hello\n']
if __name__ == '__main__':
bjoern.run(wsgi_app, '0.0.0.0', 8082)
@axiaoxin
Copy link

这个通过笔试了?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment