From e08b2cccf9eebbc6a6c8b24ff39c3179baefcd2b Mon Sep 17 00:00:00 2001 From: "roberto@maverick64" Date: Sun, 3 Jul 2011 12:55:18 +0200 Subject: [PATCH] implemented workerN signal target --- plugins/python/uwsgi_pymodule.c | 6 ++++++ signal.c | 18 ++++++++++++------ sigwait.py | 5 +++++ 3 files changed, 23 insertions(+), 6 deletions(-) diff --git a/plugins/python/uwsgi_pymodule.c b/plugins/python/uwsgi_pymodule.c index 4121baa9..841f79f9 100644 --- a/plugins/python/uwsgi_pymodule.c +++ b/plugins/python/uwsgi_pymodule.c @@ -43,6 +43,9 @@ cycle: uwsgi_error("read()"); } else { + if (uwsgi_signal_handler(received_signal)) { + uwsgi_log_verbose("error managing signal %d on worker %d\n", received_signal, uwsgi.mywid); + } wsgi_req->signal_received = received_signal; if (wait_for_specific_signal) { if (received_signal != uwsgi_signal) goto cycle; @@ -54,6 +57,9 @@ cycle: uwsgi_error("read()"); } else { + if (uwsgi_signal_handler(received_signal)) { + uwsgi_log_verbose("error managing signal %d on worker %d\n", received_signal, uwsgi.mywid); + } wsgi_req->signal_received = received_signal; if (wait_for_specific_signal) { if (received_signal != uwsgi_signal) goto cycle; diff --git a/signal.c b/signal.c index 57624883..49124c3a 100644 --- a/signal.c +++ b/signal.c @@ -172,6 +172,17 @@ void uwsgi_route_signal(uint8_t sig) { } } } + // route to specific worker + else if (!strncmp(use->receiver, "worker", 6)) { + i = atoi(use->receiver+6); + if (i > uwsgi.numproc) { + uwsgi_log("invalid signal target: %s\n", use->receiver); + } + if (write(uwsgi.workers[i].signal_pipe[0], &sig, 1) != 1) { + uwsgi_error("write()"); + uwsgi_log("could not deliver signal %d to worker %d\n", sig, i); + } + } // route to subscribed else if (!strcmp(use->receiver, "subscribed")) { } @@ -186,11 +197,6 @@ void uwsgi_route_signal(uint8_t sig) { } else { // unregistered signal, sending it to all the workers - uwsgi_log("^^^ ROUTING UNREGISTERED SIGNAL ^^^\n"); - if (write(ushared->worker_signal_pipe[0], &sig, 1) != 1) { - uwsgi_error("write()"); - uwsgi_log("could not deliver signal %d to workers pool\n", sig); - } - + uwsgi_log("^^^ UNSUPPORTED SIGNAL TARGET: %s ^^^\n", use->receiver); } } diff --git a/sigwait.py b/sigwait.py index 940b1022..30001847 100644 --- a/sigwait.py +++ b/sigwait.py @@ -5,6 +5,10 @@ from uwsgidecorators import * def hello(signum): print("I AM THE WORKER %d" % uwsgi.worker_id()) +@signal(30, target='worker2') +def hello2(signum): + print("I AM THE WORKER 2") + @postfork def wait_for_signal(): if uwsgi.worker_id() != 2: @@ -17,6 +21,7 @@ def application(e, s): s('200 OK', [('Content-Type', 'text/html')]) if e['PATH_INFO'] == '/30': uwsgi.signal(30) + uwsgi.signal(100) else: uwsgi.signal(17) return "Signal raised"