2012-04-19 14 views
1

を働いていない私はuwsgi起動すると、私はこれを呼び出すnginxの中で定義されたルートを(ヒットするまで、私は何を取得uwsgi 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" 

...私@postfork機能を実行するように見えることはできませんpy app)。ここで私は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機能を実行するために取得できますか?私の最終目標は、アプリケーション機能で接続プールを取得することです。

ありがとうございます!

更新:--wsgi-file = server.pyのために--vhostを交換すると、期待通りに動作します。

答えて

3

あなたは

と、サーバーの起動時にインポートすることができた.pyファイルにpostforkフックを移動することができます

全く捕捉可能なフォーク()を使用すると、動的なアプリを使用している場合(フォークを()すべてのアプリのロード前に発生)がありません

- モジュール名/ファイル名を変更してください

関連する問題