From 33c9d01bafbda80a47e64bd2aa7da14a8ae61306 Mon Sep 17 00:00:00 2001 From: "roberto@quantal64" Date: Tue, 19 Jun 2012 08:00:32 +0200 Subject: [PATCH] goodbye_cruel_world hook for gevent --- plugins/gevent/gevent.c | 10 ++++++++++ uwsgi.c | 13 +++++++++++-- uwsgi.h | 2 ++ 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/plugins/gevent/gevent.c b/plugins/gevent/gevent.c index 03de684a..f5f30438 100644 --- a/plugins/gevent/gevent.c +++ b/plugins/gevent/gevent.c @@ -49,6 +49,13 @@ PyObject *py_uwsgi_gevent_graceful(PyObject *self, PyObject *args) { return Py_None; } +void uwsgi_gevent_gbcw() { + + uwsgi_log("...The work of process %d is done. Seeya!\n", getpid()); + + py_uwsgi_gevent_graceful(NULL, NULL); +} + struct wsgi_request *uwsgi_gevent_current_wsgi_req(void) { PyObject *current_greenlet = GET_CURRENT_GREENLET; PyObject *py_wsgi_req = PyObject_GetAttrString(current_greenlet, "uwsgi_wsgi_req"); @@ -372,6 +379,9 @@ void gevent_loop() { i++; } + // patch goodbye_cruel_world + uwsgi.gbcw_hook = uwsgi_gevent_gbcw; + // map SIGHUP with gevent.signal PyObject *ge_signal_tuple = PyTuple_New(2); PyTuple_SetItem(ge_signal_tuple, 0, PyInt_FromLong(SIGHUP)); diff --git a/uwsgi.c b/uwsgi.c index de94368d..85a03a21 100644 --- a/uwsgi.c +++ b/uwsgi.c @@ -720,8 +720,7 @@ void end_me(int signum) { exit(UWSGI_END_CODE); } - -void goodbye_cruel_world() { +void simple_goodbye_cruel_world() { #ifdef UWSGI_THREADING if (uwsgi.threads > 1 && !uwsgi.to_hell) { @@ -734,6 +733,16 @@ void goodbye_cruel_world() { exit(0); } +void goodbye_cruel_world() { + + if (!uwsgi.gbcw_hook) { + simple_goodbye_cruel_world(); + } + else { + uwsgi.gbcw_hook(); + } +} + #ifdef UWSGI_SPOOLER static void uwsgi_signal_spoolers(int signum) { diff --git a/uwsgi.h b/uwsgi.h index 9e4ba87e..bae92084 100644 --- a/uwsgi.h +++ b/uwsgi.h @@ -1594,6 +1594,8 @@ struct uwsgi_server { void (*schedule_to_main) (struct wsgi_request *); void (*schedule_to_req) (void); + void (*gbcw_hook)(void); + int close_on_exec; char *loop;