From 69c2e568579fe5dd2e3b40ee3f655b697c866b32 Mon Sep 17 00:00:00 2001 From: "roberto@debian32" Date: Thu, 10 Nov 2011 15:36:36 +0100 Subject: [PATCH] ported python plugin to new signal_wait api --- config30.ru | 30 +++++++++++++++++ plugins/python/uwsgi_pymodule.c | 60 +++++---------------------------- 2 files changed, 38 insertions(+), 52 deletions(-) create mode 100644 config30.ru diff --git a/config30.ru b/config30.ru new file mode 100644 index 00000000..f5da1b64 --- /dev/null +++ b/config30.ru @@ -0,0 +1,30 @@ +require 'stringio' +require 'uwsgidsl' + +timer 2 do |signum| + puts "ciao sono un dsl ruby: #{signum}" +end + +=begin +timer 1,'mule' do |signum| + puts "1 second elapsed (signum #{signum})" +end + +filemon '/tmp' do |signum| + puts "/tmp has been modified" +end + +cron 5,-1,-1,-1,-1 do |signum| + puts "cron ready #{signum}" +end + +cron 58,-1,-1,-1,-1 do |signum| + puts "cron ready #{signum}" +end +=end + +run lambda { |env| + puts env.inspect + #UWSGI.signal(17) + [200, {'Content-Type'=>'text/plain'}, StringIO.new("Hello World!\n")] +} diff --git a/plugins/python/uwsgi_pymodule.c b/plugins/python/uwsgi_pymodule.c index f3d95f83..463bad4a 100644 --- a/plugins/python/uwsgi_pymodule.c +++ b/plugins/python/uwsgi_pymodule.c @@ -11,8 +11,6 @@ PyObject *py_uwsgi_signal_wait(PyObject * self, PyObject * args) { int wait_for_specific_signal = 0; uint8_t uwsgi_signal = 0; uint8_t received_signal; - int ret; - struct pollfd pfd[2]; wsgi_req->signal_received = -1; @@ -23,60 +21,18 @@ PyObject *py_uwsgi_signal_wait(PyObject * self, PyObject * args) { wait_for_specific_signal = 1; } -#ifdef UWSGI_ASYNC - if (uwsgi.async > 1) { - wsgi_req->sigwait = 1; + UWSGI_RELEASE_GIL; + + if (wait_for_specific_signal) { + received_signal = uwsgi_signal_wait(uwsgi_signal); } else { -#endif - - UWSGI_RELEASE_GIL; - - pfd[0].fd = uwsgi.signal_socket; - pfd[0].events = POLLIN; - pfd[1].fd = uwsgi.my_signal_socket; - pfd[1].events = POLLIN; -cycle: - ret = poll(pfd, 2, -1); - if (ret > 0) { - if (pfd[0].revents == POLLIN) { - if (read(uwsgi.signal_socket, &received_signal, 1) != 1) { - 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; - } - } - } - if (pfd[1].revents == POLLIN) { - if (read(uwsgi.my_signal_socket, &received_signal, 1) != 1) { - 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; - } - } - } - - } - - UWSGI_GET_GIL; - -#ifdef UWSGI_ASYNC + received_signal = uwsgi_signal_wait(-1); } -#endif + wsgi_req->signal_received = received_signal; + + UWSGI_GET_GIL; return PyString_FromString(""); }