From e86bd0c070ae6b3a252765c17405aa691b0228b8 Mon Sep 17 00:00:00 2001 From: "roberto@debian32" Date: Sat, 10 Sep 2011 17:28:01 +0200 Subject: [PATCH] preliminary support for detachable pyshell --- master.c | 1 + plugins/python/python_plugin.c | 25 +++++++++++++++++++++++-- plugins/python/uwsgi_pymodule.c | 17 +++++++++++++++-- plugins/python/uwsgi_python.h | 1 + 4 files changed, 40 insertions(+), 4 deletions(-) diff --git a/master.c b/master.c index 52779aad..6de13430 100644 --- a/master.c +++ b/master.c @@ -1328,6 +1328,7 @@ int master_loop(char **argv, char **environ) { } else { + if (uwsgi.to_heaven) { ready_to_reload++; uwsgi.workers[uwsgi.mywid].pid = 0; diff --git a/plugins/python/python_plugin.c b/plugins/python/python_plugin.c index e2e85eff..5f441bc2 100644 --- a/plugins/python/python_plugin.c +++ b/plugins/python/python_plugin.c @@ -50,7 +50,7 @@ struct option uwsgi_python_options[] = { #ifndef UWSGI_PYPY {"no-site", no_argument, &Py_NoSiteFlag, 1}, #endif - {"pyshell", no_argument, 0, LONG_ARGS_PYSHELL}, + {"pyshell", optional_argument, 0, LONG_ARGS_PYSHELL}, {0, 0, 0, 0}, }; @@ -731,7 +731,9 @@ int uwsgi_python_manage_options(int i, char *optarg) { case LONG_ARGS_PYSHELL: uwsgi.honour_stdin = 1; up.pyshell = 1; - uwsgi.to_hell = 1; + if (optarg) { + up.pyshell_pts = optarg; + } return 1; case LONG_ARGS_PYIMPORT: uwsgi_string_new_list(&up.import_list, optarg); @@ -1364,6 +1366,11 @@ void uwsgi_python_fixup() { uwsgi.p[30]->init_thread = NULL; } +int posix_openpt(int); +int grantpt(int); +int unlockpt(int); +char *ptsname(int); + void uwsgi_python_hijack(void) { // the pyshell will be execute only in the first worker @@ -1371,6 +1378,20 @@ void uwsgi_python_hijack(void) { if (up.pyshell && uwsgi.mywid == 1) { UWSGI_GET_GIL; PyImport_ImportModule("readline"); + if (up.pyshell_pts) { + + int masterfd = posix_openpt(O_RDWR|O_NOCTTY); + grantpt (masterfd); + unlockpt (masterfd); + uwsgi_log("slave = %s\n", ptsname (masterfd)); + dup2(masterfd, 0); + dup2(masterfd, 1); + dup2(masterfd, 2); + for(;;) { + PyRun_InteractiveLoop(stdin, "uwsgi"); + uwsgi_log("again !!!\n"); + } + } PyRun_InteractiveLoop(stdin, "uwsgi"); exit(0); } diff --git a/plugins/python/uwsgi_pymodule.c b/plugins/python/uwsgi_pymodule.c index 2352305f..ca2138f3 100644 --- a/plugins/python/uwsgi_pymodule.c +++ b/plugins/python/uwsgi_pymodule.c @@ -834,7 +834,7 @@ PyObject *py_uwsgi_advanced_sendfile(PyObject * self, PyObject * args) { PyObject *what; char *filename; - size_t chunk; + size_t chunk = 0; off_t pos = 0; size_t filesize = 0; struct wsgi_request *wsgi_req = current_wsgi_req(); @@ -890,7 +890,20 @@ PyObject *py_uwsgi_advanced_sendfile(PyObject * self, PyObject * args) { wsgi_req->sendfile_fd_pos = pos; // do sendfile - wsgi_req->response_size += uwsgi_sendfile(wsgi_req); + if (uwsgi.async > 1) { + ssize_t sf_len = uwsgi_sendfile(wsgi_req); + if (sf_len > 0) { + wsgi_req->response_size += sf_len; + while(wsgi_req->sendfile_fd_pos < wsgi_req->sendfile_fd_size) { + sf_len = uwsgi_sendfile(wsgi_req); + if (sf_len <= 0) break; + wsgi_req->response_size += sf_len; + } + } + } + else { + wsgi_req->response_size += uwsgi_sendfile(wsgi_req); + } // revert to old values wsgi_req->sendfile_fd = tmp_fd; diff --git a/plugins/python/uwsgi_python.h b/plugins/python/uwsgi_python.h index ce5be320..2ecfa0ec 100644 --- a/plugins/python/uwsgi_python.h +++ b/plugins/python/uwsgi_python.h @@ -128,6 +128,7 @@ struct uwsgi_python { char *test_module; int pyshell; + char *pyshell_pts; struct uwsgi_string_list *python_path; struct uwsgi_string_list *import_list;