From 55288af9364368caadbaf3994060eb9778b3ed90 Mon Sep 17 00:00:00 2001 From: "roberto@quantal64" Date: Sat, 7 Jul 2012 10:04:50 +0200 Subject: [PATCH] fixed async + threading support --- async.c | 5 +++-- plugins/python/wsgi_handlers.c | 6 +++++- proto/http.c | 2 +- tests/sleepthreadasync.py | 18 ++++++++++++++++++ 4 files changed, 27 insertions(+), 4 deletions(-) create mode 100644 tests/sleepthreadasync.py diff --git a/async.c b/async.c index 507bdf2b..1e591205 100644 --- a/async.c +++ b/async.c @@ -343,8 +343,9 @@ void *async_loop(void *arg1) { runqueue_push(uwsgi.wsgi_req); continue; } - else if (proto_parser_status == -1) { - uwsgi_log("error parsing request\n"); + else if (proto_parser_status < 0) { + if (proto_parser_status == -1) + uwsgi_log("error parsing request\n"); uwsgi.async_proto_fd_table[interesting_fd] = NULL; close(interesting_fd); continue; diff --git a/plugins/python/wsgi_handlers.c b/plugins/python/wsgi_handlers.c index bb818b39..9ed6fd84 100644 --- a/plugins/python/wsgi_handlers.c +++ b/plugins/python/wsgi_handlers.c @@ -341,6 +341,7 @@ int uwsgi_request_wsgi(struct wsgi_request *wsgi_req) { #ifdef UWSGI_ASYNC if (wsgi_req->async_status == UWSGI_AGAIN) { + UWSGI_GET_GIL // get rid of timeout if (wsgi_req->async_timed_out) { PyDict_SetItemString(wsgi_req->async_environ, "x-wsgiorg.fdevent.timeout", Py_True); @@ -357,7 +358,9 @@ int uwsgi_request_wsgi(struct wsgi_request *wsgi_req) { else { PyDict_SetItemString(wsgi_req->async_environ, "uwsgi.ready_fd", Py_None); } - return manage_python_response(wsgi_req); + int ret = manage_python_response(wsgi_req); + UWSGI_RELEASE_GIL + return ret; } #endif @@ -455,6 +458,7 @@ int uwsgi_request_wsgi(struct wsgi_request *wsgi_req) { while (wi->response_subhandler(wsgi_req) != UWSGI_OK) { #ifdef UWSGI_ASYNC if (uwsgi.async > 1) { + UWSGI_RELEASE_GIL return UWSGI_AGAIN; } else { diff --git a/proto/http.c b/proto/http.c index d4902692..ed39d8a6 100644 --- a/proto/http.c +++ b/proto/http.c @@ -262,7 +262,7 @@ int uwsgi_proto_http_parser(struct wsgi_request *wsgi_req) { int j; char *ptr; ssize_t remains; - // make this buffer configurable + // TODO make this buffer configurable char post_buf[8192]; char *post_tail = NULL; diff --git a/tests/sleepthreadasync.py b/tests/sleepthreadasync.py new file mode 100644 index 00000000..ebc759a5 --- /dev/null +++ b/tests/sleepthreadasync.py @@ -0,0 +1,18 @@ +import uwsgi +import threading +import time + +def foo(): + while True: + time.sleep(1) + print "ciao, sono un thread" + +t = threading.Thread(target=foo) +t.daemon=True +t.start() +def application(e, s): + s('200 OK', [('Content-Type','text/html')]) + for i in range(0,3): + yield uwsgi.async_sleep(1) + yield "iter: %d
" % i +