From 0a9855077049d746f53fe104e35bcb8c19c60fff Mon Sep 17 00:00:00 2001 From: "roberto@debian32" Date: Sat, 18 Jun 2011 06:58:01 +0200 Subject: [PATCH] reset random seed on grunt --- plugins/jvm/uwsgiplugin.py | 10 ++++++++ plugins/python/python_plugin.c | 41 ++++++++++++++++++--------------- plugins/python/uwsgi_pymodule.c | 3 +++ plugins/python/uwsgi_python.h | 2 ++ 4 files changed, 38 insertions(+), 18 deletions(-) diff --git a/plugins/jvm/uwsgiplugin.py b/plugins/jvm/uwsgiplugin.py index b93fc845..578e7d28 100644 --- a/plugins/jvm/uwsgiplugin.py +++ b/plugins/jvm/uwsgiplugin.py @@ -16,6 +16,16 @@ NAME='jvm' JVM_INCPATH = "/usr/lib/jvm/java-6-sun-1.6.0.15/include/ -I/usr/lib/jvm/java-6-sun-1.6.0.15/include/linux" JVM_LIBPATH = "/usr/lib/jvm/java-6-sun-1.6.0.15/jre/lib/i386/server/" +try: + JVM_INCPATH = os.environ['UWSGICONFIG_JVM_INCPATH'] +except: + pass + +try: + JVM_LIBPATH = os.environ['UWSGICONFIG_JVM_LIBPATH'] +except: + pass + try: JVM_INCPATH = os.environ['UWSGICONFIG_JVM_INCPATH'] except: diff --git a/plugins/python/python_plugin.c b/plugins/python/python_plugin.c index c6a2e510..9a1b3542 100644 --- a/plugins/python/python_plugin.c +++ b/plugins/python/python_plugin.c @@ -137,27 +137,32 @@ int uwsgi_python_init() { } -void uwsgi_python_post_fork() { +void uwsgi_python_reset_random_seed() { PyObject *random_module, *random_dict, *random_seed; - // reinitialize the random seed (thanks Jonas Borgström) - random_module = PyImport_ImportModule("random"); - if (random_module) { - random_dict = PyModule_GetDict(random_module); - if (random_dict) { - random_seed = PyDict_GetItemString(random_dict, "seed"); - if (random_seed) { - PyObject *random_args = PyTuple_New(1); - // pass no args - PyTuple_SetItem(random_args, 0, Py_None); - PyEval_CallObject(random_seed, random_args); - if (PyErr_Occurred()) { - PyErr_Print(); - } - } - } - } + // reinitialize the random seed (thanks Jonas Borgström) + random_module = PyImport_ImportModule("random"); + if (random_module) { + random_dict = PyModule_GetDict(random_module); + if (random_dict) { + random_seed = PyDict_GetItemString(random_dict, "seed"); + if (random_seed) { + PyObject *random_args = PyTuple_New(1); + // pass no args + PyTuple_SetItem(random_args, 0, Py_None); + PyEval_CallObject(random_seed, random_args); + if (PyErr_Occurred()) { + PyErr_Print(); + } + } + } + } +} + +void uwsgi_python_post_fork() { + + uwsgi_python_reset_random_seed(); #ifdef UWSGI_EMBEDDED // call the post_fork_hook diff --git a/plugins/python/uwsgi_pymodule.c b/plugins/python/uwsgi_pymodule.c index 3528ee4c..f50463dc 100644 --- a/plugins/python/uwsgi_pymodule.c +++ b/plugins/python/uwsgi_pymodule.c @@ -2215,6 +2215,9 @@ PyObject *py_uwsgi_grunt(PyObject * self, PyObject * args) { uwsgi.workers[uwsgi.mywid].id = uwsgi.mywid; // this field will be overwrite after each call uwsgi.workers[uwsgi.mywid].pid = uwsgi.mypid; + + // reset the random seed + uwsgi_python_reset_random_seed(); // TODO // manage thread in grunt processes Py_INCREF(Py_True); diff --git a/plugins/python/uwsgi_python.h b/plugins/python/uwsgi_python.h index cd778ad5..0ce04228 100644 --- a/plugins/python/uwsgi_python.h +++ b/plugins/python/uwsgi_python.h @@ -221,3 +221,5 @@ void threaded_reset_ts(struct wsgi_request *, struct uwsgi_app *); void simple_reset_ts(struct wsgi_request *, struct uwsgi_app *); int uwsgi_python_profiler_call(PyObject *, PyFrameObject *, int, PyObject *); + +void uwsgi_python_reset_random_seed(void);