@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に交換すると、期待どおりに機能します。