如何在异步模式下使用gevent运行uwsgi

时间:2014-10-21 13:36:07

标签: python uwsgi gevent

我尝试运行以下内容

# aaa.py
def application(env, sr):
    import gevent
    print "A1"
    gevent.sleep(0)
    yield
    heavy_func()
    print "A2"
    gevent.sleep(0)
    yield
    heavy_func()
    print "A3"
    sr('200 OK', [('Content-Type','text/html')])

uwsgi --gevent 10 --http :9302 --enable-threads --module aaa

当我同时连接到uwsgi时,我得到了

A1
A2
A3
[pid: 21446|app: 0|req: 1/1] 10.0.1.103 () {36 vars in 632 bytes} [Fri Oct 17 12:07:40 2014] GET / => generated 0 bytes in 19036 msecs (HTTP/1.1 200) 1 headers in 44 bytes (5 switches on core 9)
A1
A2
A3
[pid: 21446|app: 0|req: 2/2] 10.0.1.103 () {34 vars in 552 bytes} [Fri Oct 17 12:07:59 2014] GET /favicon.ico => generated 0 bytes in 18733 msecs (HTTP/1.1 200) 1 headers in 44 bytes (5 switches on core 9)
A1
A2
A3
[pid: 21446|app: 0|req: 3/3] 10.0.1.103 () {36 vars in 632 bytes} [Fri Oct 17 12:08:56 2014] GET / => generated 0 bytes in 20247 msecs (HTTP/1.1 200) 1 headers in 44 bytes (5 switches on core 9)
A1
A2
A3
[pid: 21446|app: 0|req: 4/4] 10.0.1.103 () {36 vars in 666 bytes} [Fri Oct 17 12:09:16 2014] GET /availability/ping => generated 0 bytes in 18449 msecs (HTTP/1.1 200) 1 headers in 44 bytes (5 switches on core 9)
A1
A2
A3
[pid: 21446|app: 0|req: 5/5] 10.0.1.103 () {34 vars in 552 bytes} [Fri Oct 17 12:09:34 2014] GET /favicon.ico => generated 0 bytes in 24794 msecs (HTTP/1.1 200) 1 headers in 44 bytes (5 switches on core 9)

日志显示uwsgi按顺序处理请求。我错过了什么?应该 " gevent.sleep(0)"或"收益"更改上下文并处理其他请求?

0 个答案:

没有答案