我似乎无法让我的@postfork 函数运行......
1 import uwsgi
2 from uwsgidecorators import *
3 from gevent import monkey; monkey.patch_all()
4 import sys
5 import umysql
6 import time
7
8 DB_HOST = 'stage.masked.com'
9 DB_PORT = 3306
10 DB_USER = 'masked'
11 DB_PASSWD = 'masked'
12 DB_DB = 'masked'
13
14 mysql_conn = None
15
16 @postfork
17 def zebra():
18 print "I AM ZEBRA"
19 raise
20
21 @postfork
22 def setup_pool():
23 global mysql_conn
24 mysql_conn = umysql.Connection()
25 print "HIII"
26 sys.stderr.write(str(mysql_conn.is_connected()))
27 mysql_conn.connect (DB_HOST, DB_PORT, DB_USER, DB_PASSWD, DB_DB)
28 sys.stderr.write(str(mysql_conn.is_connected()))
29
30 def application(env, start_response):
31 print "HALLO"
当我启动 uwsgi 时,我什么也得不到,直到我到达路由(在调用这个 py 应用程序的 nginx 中定义)。下面是我如何启动 uwsgi:
# uwsgi --socket=/tmp/uwsgi_server.sock --master --processes=2 --listen=4096 --disable-logging --loop gevent --async 128 --uid=www-data --gid=www-data --vhost
*** Starting uWSGI 1.1.2 (64bit) on [Thu Apr 19 23:55:32 2012] ***
compiled with version: 4.6.1 on 18 April 2012 20:10:46
current working directory: /ebs/py
detected binary path: /usr/local/bin/uwsgi
setgid() to 33
setuid() to 33
your memory page size is 4096 bytes
detected max file descriptor number: 1024
async fd table size: 1024
allocated 130048 bytes (127 KB) for 128 cores per worker.
VirtualHosting mode enabled.
lock engine: pthread mutexes
uwsgi socket 0 bound to UNIX address /tmp/uwsgi_server.sock fd 3
Python version: 2.7.2+ (default, Oct 4 2011, 20:41:12) [GCC 4.6.1]
Python main interpreter initialized at 0xbb9ad0
your server socket listen backlog is limited to 4096 connections
*** Operational MODE: preforking+async ***
*** no app loaded. going in full dynamic mode ***
*** uWSGI is running in multiple interpreter mode ***
spawned uWSGI master process (pid: 3340)
spawned uWSGI worker 1 (pid: 3341, cores: 128)
spawned uWSGI worker 2 (pid: 3342, cores: 128)
*** running gevent loop engine [addr:0x451080] ***
WSGI app 0 (mountpoint='masked.com|') ready in 0 seconds on interpreter 0xbb9ad0 pid: 3342
当我到达路线时,我得到:
HALLO
如何让我的 @postfork 函数运行?我的最终目标是在应用程序功能中获得连接池。
谢谢!
更新:如果我将 --vhost 换成 --wsgi-file=server.py,它会按预期工作。