From 5353eba35b253f18acca7251431331a2e246711a Mon Sep 17 00:00:00 2001 From: "roberto@debian32" Date: Thu, 4 Aug 2011 07:05:39 +0200 Subject: [PATCH] improved the pyshell --- plugins/python/pump_subhandler.c | 2 +- plugins/python/python_plugin.c | 3 ++- plugins/python/web3_subhandler.c | 2 +- spooler.c | 2 ++ utils.c | 2 ++ uwsgi.c | 25 +++++++++++++------------ 6 files changed, 21 insertions(+), 15 deletions(-) diff --git a/plugins/python/pump_subhandler.c b/plugins/python/pump_subhandler.c index c56290a0..10272019 100644 --- a/plugins/python/pump_subhandler.c +++ b/plugins/python/pump_subhandler.c @@ -300,7 +300,7 @@ int uwsgi_response_subhandler_pump(struct wsgi_request *wsgi_req) { } wsgi_req->socket->proto_write(wsgi_req, "\r\n", 2); - Py_INCREF(wsgi_req->async_placeholder); + Py_INCREF((PyObject *)wsgi_req->async_placeholder); if (PyString_Check((PyObject *)wsgi_req->async_placeholder)) { if ((wsize = wsgi_req->socket->proto_write(wsgi_req, PyString_AsString(wsgi_req->async_placeholder), PyString_Size(wsgi_req->async_placeholder))) < 0) { diff --git a/plugins/python/python_plugin.c b/plugins/python/python_plugin.c index 8c7b2a94..b4ba585c 100644 --- a/plugins/python/python_plugin.c +++ b/plugins/python/python_plugin.c @@ -1226,7 +1226,8 @@ void uwsgi_python_fixup() { } void uwsgi_python_hijack(void) { - if (up.pyshell) { + // the pyshell will be execute only in the first worker + if (up.pyshell && uwsgi.mywid == 1) { PyImport_ImportModule("readline"); PyRun_InteractiveLoop(stdin, "uwsgi"); exit(0); diff --git a/plugins/python/web3_subhandler.c b/plugins/python/web3_subhandler.c index c0349268..68c965ff 100644 --- a/plugins/python/web3_subhandler.c +++ b/plugins/python/web3_subhandler.c @@ -149,7 +149,7 @@ int uwsgi_response_subhandler_web3(struct wsgi_request *wsgi_req) { wsgi_req->async_placeholder = PyTuple_GetItem((PyObject *)wsgi_req->async_result, 0); - Py_INCREF(wsgi_req->async_placeholder); + Py_INCREF((PyObject *)wsgi_req->async_placeholder); PyObject *spit_args = PyTuple_New(2); diff --git a/spooler.c b/spooler.c index 884b59e4..87e55b1b 100644 --- a/spooler.c +++ b/spooler.c @@ -30,6 +30,8 @@ pid_t spooler_start() { exit(1); } else if (pid == 0) { + uwsgi.mywid = -1; + uwsgi.mypid = pid; uwsgi_close_all_sockets(); if (uwsgi.master_process) { close(uwsgi.shared->spooler_signal_pipe[0]); diff --git a/utils.c b/utils.c index 38bb0d06..ecb53c5e 100644 --- a/utils.c +++ b/utils.c @@ -2693,6 +2693,7 @@ char *uwsgi_get_binary_path(char *argvzero) { if (len > 0) { return buf; } + free(buf); #elif defined(__APPLE__) char *buf = uwsgi_malloc(uwsgi.page_size); uint32_t len = uwsgi.page_size; @@ -2729,6 +2730,7 @@ char *uwsgi_get_binary_path(char *argvzero) { if (sysctl(mib, 4, buf, &len, NULL, 0) == 0) { return buf; } + free(buf); #endif diff --git a/uwsgi.c b/uwsgi.c index 80878ef6..39e55c73 100644 --- a/uwsgi.c +++ b/uwsgi.c @@ -2200,18 +2200,6 @@ skipzero: //from now on the process is a real worker } - for (i = 0; i < 0xFF; i++) { - if (uwsgi.p[i]->hijack_worker) { - uwsgi.p[i]->hijack_worker(); - } - } - - for (i = 0; i < uwsgi.gp_cnt; i++) { - if (uwsgi.gp[i]->hijack_worker) { - uwsgi.gp[i]->hijack_worker(); - } - } - uwsgi_sock = uwsgi.sockets; while (uwsgi_sock) { @@ -2540,6 +2528,19 @@ void uwsgi_ignition() { uwsgi_log("[snapshot] process %d is the new worker %d\n", (int) getpid(), uwsgi.mywid); } + for (i = 0; i < 0xFF; i++) { + if (uwsgi.p[i]->hijack_worker) { + uwsgi.p[i]->hijack_worker(); + } + } + + for (i = 0; i < uwsgi.gp_cnt; i++) { + if (uwsgi.gp[i]->hijack_worker) { + uwsgi.gp[i]->hijack_worker(); + } + } + + if (uwsgi.loop) { void (*u_loop) (void) = uwsgi_get_loop(uwsgi.loop); uwsgi_log("running %s loop %p\n", uwsgi.loop, u_loop);