From 6db3dab5eadcdf7b73298e3e9d61440620f2e828 Mon Sep 17 00:00:00 2001 From: "roberto@oneiric64" Date: Wed, 25 Jan 2012 06:32:02 +0100 Subject: [PATCH] added --pyshell-oneshot --- plugins/python/python_plugin.c | 12 +++++++++++- plugins/python/uwsgi_python.h | 2 ++ uwsgi.h | 1 + 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/plugins/python/python_plugin.c b/plugins/python/python_plugin.c index 45ba8a20..85d98ff9 100644 --- a/plugins/python/python_plugin.c +++ b/plugins/python/python_plugin.c @@ -55,6 +55,7 @@ struct option uwsgi_python_options[] = { {"no-site", no_argument, &Py_NoSiteFlag, 1}, #endif {"pyshell", no_argument, 0, LONG_ARGS_PYSHELL}, + {"pyshell-oneshot", no_argument, 0, LONG_ARGS_PYSHELL_ONESHOT}, {"python", required_argument, 0, LONG_ARGS_PYTHON_RUN}, {"py", required_argument, 0, LONG_ARGS_PYTHON_RUN}, @@ -779,6 +780,11 @@ int uwsgi_python_manage_options(int i, char *optarg) { uwsgi.honour_stdin = 1; up.pyshell = 1; return 1; + case LONG_ARGS_PYSHELL_ONESHOT: + uwsgi.honour_stdin = 1; + up.pyshell = 1; + up.pyshell_oneshot = 1; + return 1; case LONG_ARGS_SHARED_PYIMPORT: uwsgi_string_new_list(&up.shared_import_list, optarg); return 1; @@ -1484,8 +1490,12 @@ void uwsgi_python_hijack(void) { // the pyshell will be execute only in the first worker #ifndef UWSGI_PYPY + if (up.pyshell_oneshot && uwsgi.workers[uwsgi.mywid].hijacked_count > 0) { + uwsgi.workers[uwsgi.mywid].hijacked = 0; + return; + } if (up.pyshell && uwsgi.mywid == 1) { - uwsgi.workers[uwsgi.mywid].hijacked = 1; + uwsgi.workers[uwsgi.mywid].hijacked_count++; // re-map stdin to stdout and stderr if we are logging to a file if (uwsgi.logfile) { if (dup2(0, 1) < 0) { diff --git a/plugins/python/uwsgi_python.h b/plugins/python/uwsgi_python.h index dee978c5..d2ea10b9 100644 --- a/plugins/python/uwsgi_python.h +++ b/plugins/python/uwsgi_python.h @@ -22,6 +22,7 @@ #define LONG_ARGS_SPOOLER_PYIMPORT LONG_ARGS_PYTHON_BASE + 12 #define LONG_ARGS_PYTHON_RUN LONG_ARGS_PYTHON_BASE + 13 #define LONG_ARGS_SHARED_PYIMPORT LONG_ARGS_PYTHON_BASE + 14 +#define LONG_ARGS_PYSHELL_ONESHOT LONG_ARGS_PYTHON_BASE + 15 #define PYTHON_APP_TYPE_WSGI 0 #define PYTHON_APP_TYPE_WEB3 1 @@ -131,6 +132,7 @@ struct uwsgi_python { char *test_module; int pyshell; + int pyshell_oneshot; struct uwsgi_string_list *python_path; struct uwsgi_string_list *import_list; diff --git a/uwsgi.h b/uwsgi.h index 29e4ed59..250d3474 100644 --- a/uwsgi.h +++ b/uwsgi.h @@ -1849,6 +1849,7 @@ struct uwsgi_worker { uint64_t tx; int hijacked; + uint64_t hijacked_count; int busy; int cheaped; int suspended;