From 33df0dbcc95acc2fdef56aba8da2a5fc653e6571 Mon Sep 17 00:00:00 2001 From: Unbit Date: Thu, 10 Sep 2015 09:35:53 +0200 Subject: [PATCH] attempt to fix #1034 --- plugins/python/python_plugin.c | 9 ++++++--- plugins/python/uwsgi_python.h | 3 +++ plugins/python/wsgi_handlers.c | 2 ++ 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/plugins/python/python_plugin.c b/plugins/python/python_plugin.c index 5628b980..cc02082d 100644 --- a/plugins/python/python_plugin.c +++ b/plugins/python/python_plugin.c @@ -204,15 +204,18 @@ struct uwsgi_option uwsgi_python_options[] = { /* this routine will be called after each fork to reinitialize the various locks */ void uwsgi_python_pthread_prepare(void) { - pthread_mutex_lock(&up.lock_pyloaders); + if (!up.is_dynamically_loading_an_app) + pthread_mutex_lock(&up.lock_pyloaders); } void uwsgi_python_pthread_parent(void) { - pthread_mutex_unlock(&up.lock_pyloaders); + if (!up.is_dynamically_loading_an_app) + pthread_mutex_unlock(&up.lock_pyloaders); } void uwsgi_python_pthread_child(void) { - pthread_mutex_init(&up.lock_pyloaders, NULL); + if (!up.is_dynamically_loading_an_app) + pthread_mutex_init(&up.lock_pyloaders, NULL); } PyMethodDef uwsgi_spit_method[] = { {"uwsgi_spit", py_uwsgi_spit, METH_VARARGS, ""} }; diff --git a/plugins/python/uwsgi_python.h b/plugins/python/uwsgi_python.h index 1c046972..aaf73ca3 100644 --- a/plugins/python/uwsgi_python.h +++ b/plugins/python/uwsgi_python.h @@ -213,6 +213,9 @@ struct uwsgi_python { int call_osafterfork; int pre_initialized; + + // when 1 we have the app-loading lock held + int is_dynamically_loading_an_app; }; diff --git a/plugins/python/wsgi_handlers.c b/plugins/python/wsgi_handlers.c index c9bb2db4..d058e128 100644 --- a/plugins/python/wsgi_handlers.c +++ b/plugins/python/wsgi_handlers.c @@ -339,6 +339,7 @@ int uwsgi_request_wsgi(struct wsgi_request *wsgi_req) { // this part must be heavy locked in threaded modes if (uwsgi.threads > 1) { pthread_mutex_lock(&up.lock_pyloaders); + up.is_dynamically_loading_an_app = 1; } } @@ -363,6 +364,7 @@ int uwsgi_request_wsgi(struct wsgi_request *wsgi_req) { if (wsgi_req->dynamic) { if (uwsgi.threads > 1) { + up.is_dynamically_loading_an_app = 0; pthread_mutex_unlock(&up.lock_pyloaders); } }