Browse files

implemented workerN signal target

  • Loading branch information...
1 parent 0ba1b98 commit e08b2cccf9eebbc6a6c8b24ff39c3179baefcd2b roberto@maverick64 committed Jul 3, 2011
Showing with 23 additions and 6 deletions.
  1. +6 −0 plugins/python/uwsgi_pymodule.c
  2. +12 −6 signal.c
  3. +5 −0 sigwait.py
View
6 plugins/python/uwsgi_pymodule.c
@@ -43,6 +43,9 @@ PyObject *py_uwsgi_signal_wait(PyObject * self, PyObject * args) {
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 @@ PyObject *py_uwsgi_signal_wait(PyObject * self, PyObject * args) {
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;
View
18 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);
}
}
View
5 sigwait.py
@@ -5,6 +5,10 @@
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"

0 comments on commit e08b2cc

Please sign in to comment.