Skip to content

Commit

Permalink
ported python plugin to new signal_wait api
Browse files Browse the repository at this point in the history
  • Loading branch information
roberto@debian32 committed Nov 10, 2011
1 parent 18f7d1e commit 69c2e56
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 52 deletions.
30 changes: 30 additions & 0 deletions config30.ru
Original file line number Diff line number Diff line change
@@ -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")]
}
60 changes: 8 additions & 52 deletions plugins/python/uwsgi_pymodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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("");
}
Expand Down

0 comments on commit 69c2e56

Please sign in to comment.