applications list is now shared

This commit is contained in:
roberto@debian32
2011-08-12 08:08:39 +02:00
parent 287df9ef86
commit a19b392ba6
42 changed files with 1193 additions and 446 deletions
+1 -1
View File
@@ -172,7 +172,7 @@ void *uwsgi_request_subhandler_pump(struct wsgi_request *wsgi_req, struct uwsgi_
// call
PyTuple_SetItem(wsgi_req->async_args, 0, wsgi_req->async_environ);
return python_call(wsgi_req->async_app, wsgi_req->async_args, uwsgi.catch_exceptions);
return python_call(wsgi_req->async_app, wsgi_req->async_args, uwsgi.catch_exceptions, wsgi_req);
}
+12 -4
View File
@@ -26,7 +26,7 @@ int init_uwsgi_app(int loader, void *arg1, struct wsgi_request *wsgi_req, PyThre
PyObject *app_list = NULL, *applications = NULL;
int id = uwsgi.apps_cnt;
int id = uwsgi_apps_cnt;
int multiapp = 0;
#ifdef UWSGI_ASYNC
@@ -47,7 +47,7 @@ int init_uwsgi_app(int loader, void *arg1, struct wsgi_request *wsgi_req, PyThre
}
wi = &uwsgi.apps[id];
wi = &uwsgi_apps[id];
memset(wi, 0, sizeof(struct uwsgi_app));
wi->mountpoint = mountpoint;
@@ -310,7 +310,7 @@ int init_uwsgi_app(int loader, void *arg1, struct wsgi_request *wsgi_req, PyThre
uwsgi.default_app = id;
}
uwsgi.apps_cnt++;
uwsgi_apps_cnt++;
uwsgi_rawlog("\n");
@@ -328,6 +328,14 @@ int init_uwsgi_app(int loader, void *arg1, struct wsgi_request *wsgi_req, PyThre
}
}
// check if we need to emulate fork() COW
if (uwsgi.mywid == 0) {
for(i=1;i<=uwsgi.numproc;i++) {
memcpy(&uwsgi.workers[i].apps[id], &uwsgi.workers[0].apps[id], sizeof(struct uwsgi_app));
uwsgi.workers[i].apps_cnt = uwsgi_apps_cnt;
}
}
return id;
doh:
@@ -423,7 +431,7 @@ PyObject *uwsgi_uwsgi_loader(void *arg1) {
tmp_callable = PyDict_GetItemString(wsgi_dict, quick_callable);
quick_callable[strlen(quick_callable)] = '(';
if (tmp_callable) {
return python_call(tmp_callable, PyTuple_New(0), 0);
return python_call(tmp_callable, PyTuple_New(0), 0, NULL);
}
}
+6 -6
View File
@@ -194,7 +194,7 @@ void uwsgi_python_post_fork() {
if (uwsgi_dict) {
PyObject *pfh = PyDict_GetItemString(uwsgi_dict, "post_fork_hook");
if (pfh) {
python_call(pfh, PyTuple_New(0), 0);
python_call(pfh, PyTuple_New(0), 0, NULL);
}
}
PyErr_Clear();
@@ -790,8 +790,8 @@ int uwsgi_python_manage_options(int i, char *optarg) {
int uwsgi_python_mount_app(char *mountpoint, char *app) {
uwsgi.wsgi_req->script_name = mountpoint;
uwsgi.wsgi_req->script_name_len = strlen(mountpoint);
uwsgi.wsgi_req->appid = mountpoint;
uwsgi.wsgi_req->appid_len = strlen(mountpoint);
if (uwsgi.single_interpreter) {
return init_uwsgi_app(LOADER_MOUNT, app, uwsgi.wsgi_req, up.main_thread, PYTHON_APP_TYPE_WSGI);
}
@@ -1124,7 +1124,7 @@ int uwsgi_python_signal_handler(uint8_t sig, void *handler) {
PyTuple_SetItem(args, 0, PyInt_FromLong(sig));
ret = python_call(handler, args, 0);
ret = python_call(handler, args, 0, NULL);
if (ret) {
UWSGI_RELEASE_GIL;
@@ -1151,7 +1151,7 @@ uint16_t uwsgi_python_rpc(void *func, uint8_t argc, char **argv, char *buffer) {
PyTuple_SetItem(pyargs, i, PyString_FromString(argv[i]));
}
ret = python_call((PyObject *) func, pyargs, 0);
ret = python_call((PyObject *) func, pyargs, 0, NULL);
if (ret) {
if (PyString_Check(ret)) {
@@ -1222,7 +1222,7 @@ int uwsgi_python_spooler(char *filename, char *buf, uint16_t len, char *body, si
}
PyTuple_SetItem(pyargs, 0, spool_dict);
ret = python_call(spool_func, pyargs, 0);
ret = python_call(spool_func, pyargs, 0, NULL);
if (ret) {
if (!PyInt_Check(ret)) {
+7 -3
View File
@@ -8,7 +8,7 @@ int manage_python_response(struct wsgi_request *wsgi_req) {
return uwsgi_response_subhandler_wsgi(wsgi_req);
}
PyObject *python_call(PyObject *callable, PyObject *args, int catch) {
PyObject *python_call(PyObject *callable, PyObject *args, int catch, struct wsgi_request *wsgi_req) {
PyObject *pyret;
@@ -23,8 +23,12 @@ PyObject *python_call(PyObject *callable, PyObject *args, int catch) {
uwsgi_log("Memory Error detected !!!\n");
}
// this can be in a spooler or in the master
if (uwsgi.mywid > 0)
if (uwsgi.mywid > 0) {
uwsgi.workers[uwsgi.mywid].exceptions++;
if (wsgi_req) {
uwsgi_apps[wsgi_req->app_id].exceptions++;
}
}
if (!catch) {
PyErr_Print();
}
@@ -41,7 +45,7 @@ PyObject *python_call(PyObject *callable, PyObject *args, int catch) {
int uwsgi_python_call(struct wsgi_request *wsgi_req, PyObject *callable, PyObject *args) {
wsgi_req->async_result = python_call(callable, args, 0);
wsgi_req->async_result = python_call(callable, args, 0, wsgi_req);
if (wsgi_req->async_result) {
while ( manage_python_response(wsgi_req) != UWSGI_OK) {
+41 -2
View File
@@ -2081,8 +2081,9 @@ PyObject *py_uwsgi_total_requests(PyObject * self, PyObject * args) {
/* uWSGI workers */
PyObject *py_uwsgi_workers(PyObject * self, PyObject * args) {
PyObject *worker_dict, *zero;
int i;
PyObject *worker_dict, *apps_dict, *apps_tuple, *zero;
int i, j;
struct uwsgi_app *ua;
for (i = 0; i < uwsgi.numproc; i++) {
worker_dict = PyTuple_GetItem(up.workers_tuple, i);
@@ -2155,6 +2156,43 @@ PyObject *py_uwsgi_workers(PyObject * self, PyObject * args) {
Py_DECREF(zero);
*/
apps_tuple = PyTuple_New(uwsgi.workers[i+1].apps_cnt);
for(j=0;j<uwsgi.workers[i+1].apps_cnt;j++) {
apps_dict = PyDict_New();
ua = &uwsgi.workers[i+1].apps[j];
PyDict_SetItemString(apps_dict, "id", PyInt_FromLong(j));
PyDict_SetItemString(apps_dict, "modifier1", PyInt_FromLong(ua->modifier1));
zero = PyString_FromStringAndSize(ua->mountpoint, ua->mountpoint_len);
PyDict_SetItemString(apps_dict, "mountpoint", zero);
Py_DECREF(zero);
PyDict_SetItemString(apps_dict, "interpreter", PyInt_FromLong((long)ua->interpreter));
PyDict_SetItemString(apps_dict, "callable", PyInt_FromLong((long)ua->interpreter));
PyDict_SetItemString(apps_dict, "requests", PyInt_FromLong(ua->requests));
PyDict_SetItemString(apps_dict, "exceptions", PyInt_FromLong(ua->exceptions));
if (ua->chdir) {
zero = PyString_FromString(ua->chdir);
}
else {
zero = PyString_FromString("");
}
PyDict_SetItemString(apps_dict, "chdir", zero);
Py_DECREF(zero);
PyTuple_SetItem(apps_tuple, j, apps_dict);
}
PyDict_SetItemString(worker_dict, "apps", apps_tuple);
Py_DECREF(apps_tuple);
}
@@ -2169,6 +2207,7 @@ PyObject *py_uwsgi_workers(PyObject * self, PyObject * args) {
}
/* uWSGI reload */
PyObject *py_uwsgi_reload(PyObject * self, PyObject * args) {
+1 -1
View File
@@ -202,7 +202,7 @@ PyObject *py_eventfd_write(PyObject *, PyObject *);
int manage_python_response(struct wsgi_request *);
int uwsgi_python_call(struct wsgi_request *, PyObject *, PyObject *);
PyObject *python_call(PyObject *, PyObject *, int);
PyObject *python_call(PyObject *, PyObject *, int, struct wsgi_request *);
#ifdef UWSGI_SENDFILE
PyObject *py_uwsgi_sendfile(PyObject *, PyObject *);
+1 -1
View File
@@ -127,7 +127,7 @@ void *uwsgi_request_subhandler_web3(struct wsgi_request *wsgi_req, struct uwsgi_
// call
PyTuple_SetItem(wsgi_req->async_args, 0, wsgi_req->async_environ);
return python_call(wsgi_req->async_app, wsgi_req->async_args, uwsgi.catch_exceptions);
return python_call(wsgi_req->async_app, wsgi_req->async_args, uwsgi.catch_exceptions, wsgi_req);
}
+2 -2
View File
@@ -372,7 +372,7 @@ int uwsgi_request_wsgi(struct wsgi_request *wsgi_req) {
wsgi_req->appid = uwsgi_concat3n(wsgi_req->host, wsgi_req->host_len, "|",1, wsgi_req->script_name, wsgi_req->script_name_len);
wsgi_req->appid_len = wsgi_req->host_len + 1 + wsgi_req->script_name_len;
#ifdef UWSGI_DEBUG
uwsgi_debug("VirtualHost SCRIPT_NAME=%s\n", what);
uwsgi_debug("VirtualHost KEY=%.*s\n", wsgi_req->appid_len, wsgi_req->appid);
#endif
free_appid = 1;
}
@@ -414,7 +414,7 @@ int uwsgi_request_wsgi(struct wsgi_request *wsgi_req) {
goto clear2;
}
wi = &uwsgi.apps[wsgi_req->app_id];
wi = &uwsgi_apps[wsgi_req->app_id];
up.swap_ts(wsgi_req, wi);
+2 -1
View File
@@ -152,7 +152,7 @@ void *uwsgi_request_subhandler_wsgi(struct wsgi_request *wsgi_req, struct uwsgi_
PyTuple_SetItem(wsgi_req->async_args, 0, wsgi_req->async_environ);
return python_call(wsgi_req->async_app, wsgi_req->async_args, up.catch_exceptions);
return python_call(wsgi_req->async_app, wsgi_req->async_args, up.catch_exceptions, wsgi_req);
}
int uwsgi_response_subhandler_wsgi(struct wsgi_request *wsgi_req) {
@@ -219,6 +219,7 @@ int uwsgi_response_subhandler_wsgi(struct wsgi_request *wsgi_req) {
uwsgi_log("Memory Error detected !!!\n");
}
uwsgi.workers[uwsgi.mywid].exceptions++;
uwsgi_apps[wsgi_req->app_id].exceptions++;
PyErr_Print();
}
goto clear;