From 2246d30bbe04ebbeebe2b9c7222050deaa608bb4 Mon Sep 17 00:00:00 2001 From: "roberto@debian32" Date: Fri, 24 Jun 2011 19:42:01 +0200 Subject: [PATCH] fixed threaded loading --- buildconf/default.ini | 2 +- multiapp.py | 11 +++-------- plugins/python/gil.c | 4 ++-- plugins/python/pyloader.c | 1 + plugins/python/python_plugin.c | 4 ---- rpc.c | 5 +++++ uwsgi.c | 20 +++++++++----------- 7 files changed, 21 insertions(+), 26 deletions(-) diff --git a/buildconf/default.ini b/buildconf/default.ini index 47217e31..f36b4d1f 100644 --- a/buildconf/default.ini +++ b/buildconf/default.ini @@ -18,7 +18,7 @@ async = true evdis = false ldap = auto pcre = auto -debug = true +debug = false unbit = false xml_implementation = libxml2 yaml_implementation = auto diff --git a/multiapp.py b/multiapp.py index a844b4fd..5b2f1125 100644 --- a/multiapp.py +++ b/multiapp.py @@ -1,14 +1,9 @@ import werkzeug - -def web3_app(environ): - status = b'200 OK' - headers = [(b'Content-type', b'text/plain')] - body = [b'I am a Web3 app\n'] - return body, status, headers +import uwsgi def zero_app(e,s): s('200 OK', [ ('Content-Type', 'text/plain') ]) - return "" + return "0" def not_found(e,s): s('404 Not Found', [ ('Content-Type', 'text/plain') ]) @@ -24,4 +19,4 @@ def internal_server_error(e, s): s('500 Internal Server Error', [ ('Content-Type', 'text/plain') ]) return "" -applications = {'':web3_app, '/wsgi':wsgi_app, '/test':werkzeug.test_app, '/zero':zero_app, '/notfound':not_found, '/ise':internal_server_error} +uwsgi.applications = {'/wsgi':wsgi_app, '/test':werkzeug.test_app, '/zero':zero_app, '/notfound':not_found, '/ise':internal_server_error} diff --git a/plugins/python/gil.c b/plugins/python/gil.c index b84b0233..a1f4544f 100644 --- a/plugins/python/gil.c +++ b/plugins/python/gil.c @@ -4,7 +4,7 @@ extern struct uwsgi_server uwsgi; extern struct uwsgi_python up; void gil_real_get() { - uwsgi_log("LOCK %d\n", uwsgi.mywid); + //uwsgi_log("LOCK %d\n", uwsgi.mywid); #ifndef PYTHREE PyEval_AcquireLock(); PyThreadState_Swap((PyThreadState *) pthread_getspecific(up.upt_gil_key)); @@ -14,7 +14,7 @@ void gil_real_get() { } void gil_real_release() { - uwsgi_log("UNLOCK %d\n", uwsgi.mywid); + //uwsgi_log("UNLOCK %d\n", uwsgi.mywid); #ifndef PYTHREE pthread_setspecific(up.upt_gil_key, (void *) PyThreadState_Swap(NULL)); PyEval_ReleaseLock(); diff --git a/plugins/python/pyloader.c b/plugins/python/pyloader.c index 59860a80..771ec8ab 100644 --- a/plugins/python/pyloader.c +++ b/plugins/python/pyloader.c @@ -303,6 +303,7 @@ int init_uwsgi_app(int loader, void *arg1, struct wsgi_request *wsgi_req, PyThre if (uwsgi.threads > 1 && id) { // if we have multiple threads we need to initialize a PyThreadState for each one for(i=0;its[id]); uwsgi.core[i]->ts[id] = PyThreadState_New( ((PyThreadState *)wi->interpreter)->interp); if (!uwsgi.core[i]->ts[id]) { uwsgi_log("unable to allocate new PyThreadState structure for app %s", mountpoint); diff --git a/plugins/python/python_plugin.c b/plugins/python/python_plugin.c index 8683cd56..a3cf4c06 100644 --- a/plugins/python/python_plugin.c +++ b/plugins/python/python_plugin.c @@ -162,8 +162,6 @@ void uwsgi_python_reset_random_seed() { void uwsgi_python_post_fork() { - uwsgi_log("POST FORK %d\n", uwsgi.mywid); - uwsgi_python_reset_random_seed(); #ifdef UWSGI_EMBEDDED @@ -178,8 +176,6 @@ void uwsgi_python_post_fork() { PyErr_Clear(); #endif - uwsgi_log("RELEASING GIL %d\n", uwsgi.mywid); - UWSGI_RELEASE_GIL } diff --git a/rpc.c b/rpc.c index baca7e3e..492b9278 100644 --- a/rpc.c +++ b/rpc.c @@ -7,6 +7,11 @@ int uwsgi_register_rpc(char *name, uint8_t modifier1, uint8_t args, void *func) struct uwsgi_rpc *urpc; int ret = -1; + if (uwsgi.mywid != 0) { + uwsgi_log("you can register RPC functions only in the master\n"); + return -1; + } + uwsgi_lock(uwsgi.rpc_table_lock); if (uwsgi.shared->rpc_count < MAX_RPC) { diff --git a/uwsgi.c b/uwsgi.c index e3546e2b..14d3342d 100644 --- a/uwsgi.c +++ b/uwsgi.c @@ -1970,6 +1970,15 @@ int uwsgi_start(void *v_argv) { uwsgi_rawlog(" ***\n"); + // even the master has cores.. + uwsgi.core = uwsgi_malloc(sizeof(struct uwsgi_core *) * uwsgi.cores); + for (j = 0; j < uwsgi.cores; j++) { + uwsgi.core[j] = uwsgi_malloc(sizeof(struct uwsgi_core)); + memset(uwsgi.core[j], 0, sizeof(struct uwsgi_core)); + } + + + //init apps hook (if not lazy) if (!uwsgi.lazy) { uwsgi_init_all_apps(); @@ -2063,8 +2072,6 @@ int uwsgi_start(void *v_argv) { //from now on the process is a real worker } - uwsgi_log("running workers...\n"); - uwsgi_sock = uwsgi.sockets; while (uwsgi_sock) { struct uwsgi_string_list *usl = uwsgi.map_socket; @@ -2172,12 +2179,6 @@ int uwsgi_start(void *v_argv) { exit(1); } - uwsgi.core = uwsgi_malloc(sizeof(struct uwsgi_core *) * uwsgi.cores); - for (j = 0; j < uwsgi.cores; j++) { - uwsgi.core[j] = uwsgi_malloc(sizeof(struct uwsgi_core)); - memset(uwsgi.core[j], 0, sizeof(struct uwsgi_core)); - } - if (uwsgi.master_as_root) { uwsgi_as_root(); } @@ -2186,15 +2187,12 @@ int uwsgi_start(void *v_argv) { uwsgi_init_all_apps(); } - uwsgi_log("post fork hook %d\n", uwsgi.mywid); for (i = 0; i < 0xFF; i++) { if (uwsgi.p[i]->post_fork) { uwsgi.p[i]->post_fork(); } } - uwsgi_log("post fork hook DONE %d\n", uwsgi.mywid); - #ifdef UWSGI_ZEROMQ if (uwsgi.zmq_receiver && uwsgi.zmq_responder) { uwsgi.zmq_context = zmq_init(1);