From 74a9b1b41d821ea80ab297e290faf6db183ce801 Mon Sep 17 00:00:00 2001 From: "roberto@precise64" Date: Tue, 24 Apr 2012 21:50:00 +0200 Subject: [PATCH] added uwsgi.ready() --- plugins/gevent/gevent.c | 4 ++++ plugins/python/python_plugin.c | 4 ++++ plugins/python/uwsgi_pymodule.c | 13 +++++++++++++ runningthread.py | 3 ++- uwsgi.h | 4 +++- 5 files changed, 26 insertions(+), 2 deletions(-) diff --git a/plugins/gevent/gevent.c b/plugins/gevent/gevent.c index d1d5022d..ab407543 100644 --- a/plugins/gevent/gevent.c +++ b/plugins/gevent/gevent.c @@ -225,6 +225,10 @@ PyMethodDef uwsgi_gevent_signal_handler_def[] = { {"uwsgi_gevent_signal_handler" void gevent_loop() { + if (!uwsgi.has_threads && uwsgi.mywid == 1) { + uwsgi_log("!!! Running gevent without threads IS NOT recommended, enable them with --enable-threads !!!\n"); + } + // get the GIL UWSGI_GET_GIL diff --git a/plugins/python/python_plugin.c b/plugins/python/python_plugin.c index a0b06759..35a89a58 100644 --- a/plugins/python/python_plugin.c +++ b/plugins/python/python_plugin.c @@ -189,6 +189,10 @@ int uwsgi_python_init() { Py_Initialize(); + if (!uwsgi.has_threads) { + uwsgi_log("*** Python threads support is disabled. You can enable it with --enable-threads ***\n"); + } + up.wsgi_spitout = PyCFunction_New(uwsgi_spit_method, NULL); up.wsgi_writeout = PyCFunction_New(uwsgi_write_method, NULL); diff --git a/plugins/python/uwsgi_pymodule.c b/plugins/python/uwsgi_pymodule.c index 955c3b0c..e2fd0ddc 100644 --- a/plugins/python/uwsgi_pymodule.c +++ b/plugins/python/uwsgi_pymodule.c @@ -1025,6 +1025,17 @@ PyObject *py_uwsgi_setprocname(PyObject * self, PyObject * args) { return Py_None; } +PyObject *py_uwsgi_ready(PyObject * self, PyObject * args) { + + if (ushared->ready) { + Py_INCREF(Py_True); + return Py_True; + } + + Py_INCREF(Py_None); + return Py_None; +} + PyObject *py_uwsgi_in_farm(PyObject * self, PyObject * args) { char *farm_name = NULL; @@ -3103,6 +3114,8 @@ static PyMethodDef uwsgi_advanced_methods[] = { {"mule_get_msg", (PyCFunction) py_uwsgi_mule_get_msg, METH_VARARGS|METH_KEYWORDS, ""}, {"farm_get_msg", py_uwsgi_farm_get_msg, METH_VARARGS, ""}, {"in_farm", py_uwsgi_in_farm, METH_VARARGS, ""}, + + {"ready", py_uwsgi_ready, METH_VARARGS, ""}, //{"call_hook", py_uwsgi_call_hook, METH_VARARGS, ""}, {NULL, NULL}, diff --git a/runningthread.py b/runningthread.py index bcd4cfe0..c13f7ca1 100644 --- a/runningthread.py +++ b/runningthread.py @@ -5,7 +5,8 @@ import uwsgi def mess(): while True: for i in xrange(0, 100): - uwsgi.signal(17) + if uwsgi.ready(): + uwsgi.signal(17) print(i) time.sleep(0.1) diff --git a/uwsgi.h b/uwsgi.h index c8a9f04e..d90035a0 100644 --- a/uwsgi.h +++ b/uwsgi.h @@ -24,7 +24,7 @@ extern "C" { #define uwsgi_str(x) uwsgi_concat2(x, "") #define uwsgi_notify(x) if (uwsgi.notify) uwsgi.notify(x) -#define uwsgi_notify_ready() if (uwsgi.notify_ready) uwsgi.notify_ready() +#define uwsgi_notify_ready() uwsgi.shared->ready = 1 ; if (uwsgi.notify_ready) uwsgi.notify_ready() #define uwsgi_apps uwsgi.workers[uwsgi.mywid].apps #define uwsgi_apps_cnt uwsgi.workers[uwsgi.mywid].apps_cnt @@ -1811,6 +1811,8 @@ struct uwsgi_shared { struct uwsgi_gateway gateways[MAX_GATEWAYS]; int gateways_cnt; time_t gateways_harakiri[MAX_GATEWAYS]; + + int ready; }; struct uwsgi_core {