From d2b52b466366ee27cb56ec7415a5252aae3adc05 Mon Sep 17 00:00:00 2001 From: "roberto@debian32" Date: Sun, 16 Oct 2011 10:37:26 +0200 Subject: [PATCH] added uwsgi.setprocname() --- plugins/python/uwsgi_pymodule.c | 15 +++++++++++++++ welcome.py | 10 ++++++++++ 2 files changed, 25 insertions(+) diff --git a/plugins/python/uwsgi_pymodule.c b/plugins/python/uwsgi_pymodule.c index a001b2aa..93bf0d22 100644 --- a/plugins/python/uwsgi_pymodule.c +++ b/plugins/python/uwsgi_pymodule.c @@ -1072,6 +1072,19 @@ PyObject *py_uwsgi_embedded_data(PyObject * self, PyObject * args) { } +PyObject *py_uwsgi_setprocname(PyObject * self, PyObject * args) { + char *name = NULL; + + if (!PyArg_ParseTuple(args, "s:setprocname", &name)) { + return NULL; + } + + uwsgi_set_processname(name); + + Py_INCREF(Py_None); + return Py_None; +} + PyObject *py_uwsgi_mule_msg(PyObject * self, PyObject * args) { char *message = NULL; @@ -2810,6 +2823,8 @@ static PyMethodDef uwsgi_advanced_methods[] = { {"unlock", py_uwsgi_unlock, METH_VARARGS, ""}, {"cl", py_uwsgi_cl, METH_VARARGS, ""}, + {"setprocname", py_uwsgi_setprocname, METH_VARARGS, ""}, + {"listen_queue", py_uwsgi_listen_queue, METH_VARARGS, ""}, {"attach_daemon", py_uwsgi_attach_daemon, METH_VARARGS, ""}, diff --git a/welcome.py b/welcome.py index eb3355b2..882252bb 100644 --- a/welcome.py +++ b/welcome.py @@ -2,6 +2,7 @@ import uwsgi import os import gc import sys +from uwsgidecorators import * gc.set_debug(gc.DEBUG_SAVEALL) print os.environ @@ -42,10 +43,19 @@ routes['/logo'] = serve_logo routes['/config'] = serve_config routes['/options'] = serve_options +@postfork +def setprocname(): + if uwsgi.worker_id() > 0: + uwsgi.setprocname("i am the worker %d" % uwsgi.worker_id()) + def application(env, start_response): uwsgi.mule_msg(env['REQUEST_URI'], 1) + req = uwsgi.workers()[uwsgi.worker_id()-1]['requests'] + + uwsgi.setprocname("worker %d managed %d requests" % (uwsgi.worker_id(), req)) + gc.collect(2) if DEBUG: print env['wsgi.input'].fileno()