prefork/multithread uwsgi.signal_wait() implementation

This commit is contained in:
roberto@maverick64
2011-07-03 12:00:06 +02:00
parent 5ed59690a0
commit 374c02c46e
5 changed files with 65 additions and 2 deletions
+37 -1
View File
@@ -10,8 +10,44 @@ extern struct uwsgi_python up;
PyObject *py_uwsgi_signal_wait(PyObject * self, PyObject * args) {
struct wsgi_request *wsgi_req = current_wsgi_req();
int wait_for_specific_signal = 0;
uint8_t uwsgi_signal = 0;
uint8_t received_signal;
int ret;
wsgi_req->signal_received = -1;
if (PyTuple_Size(args) > 0) {
if (!PyArg_ParseTuple(args, "|B:", &uwsgi_signal)) {
return NULL;
}
wait_for_specific_signal = 1;
}
#ifdef UWSGI_ASYNC
if (uwsgi.async > 1) {
wsgi_req->sigwait = 1;
}
else {
#endif
cycle:
ret = uwsgi_waitfd(uwsgi.signal_socket, -1);
if (ret > 0) {
if (read(uwsgi.signal_socket, &received_signal, 1) != 1) {
uwsgi_error("read()");
}
else {
wsgi_req->signal_received = received_signal;
if (wait_for_specific_signal) {
if (received_signal != uwsgi_signal) goto cycle;
}
}
}
#ifdef UWSGI_ASYNC
}
#endif
wsgi_req->sigwait = 1;
return PyString_FromString("");
}