From 12bf2cd3af38f7fc6468e900f4063aa1ad23ffe6 Mon Sep 17 00:00:00 2001 From: Unbit Date: Tue, 19 Feb 2013 07:11:45 +0100 Subject: [PATCH] fixed exception management in python mules and improved uwsgidecorators --- core/exceptions.c | 3 ++- core/mule.c | 2 +- plugins/python/pyutils.c | 7 ++++++- uwsgidecorators.py | 15 +++++++++++++-- 4 files changed, 22 insertions(+), 5 deletions(-) diff --git a/core/exceptions.c b/core/exceptions.c index 00e0da56..1d6da07a 100644 --- a/core/exceptions.c +++ b/core/exceptions.c @@ -245,7 +245,7 @@ void uwsgi_manage_exception(struct wsgi_request *wsgi_req,int catch) { goto check_catch; } - if (!wsgi_req) goto log; + if (!wsgi_req) goto log2; uwsgi.workers[uwsgi.mywid].cores[wsgi_req->async_id].exceptions++; uwsgi_apps[wsgi_req->app_id].exceptions++; @@ -311,6 +311,7 @@ log: uwsgi.p[wsgi_req->uh->modifier1]->exception_log(wsgi_req); } +log2: if (do_exit) { exit(UWSGI_EXCEPTION_CODE); } diff --git a/core/mule.c b/core/mule.c index 12a6fda7..9cc1e31e 100644 --- a/core/mule.c +++ b/core/mule.c @@ -81,7 +81,7 @@ void uwsgi_mule(int id) { for (i = 0; i < 256; i++) { if (uwsgi.p[i]->mule) { if (uwsgi.p[i]->mule(uwsgi.mules[id - 1].patch) == 1) { - // never here + // never here ? end_me(1); } } diff --git a/plugins/python/pyutils.c b/plugins/python/pyutils.c index b258931e..837c6c18 100644 --- a/plugins/python/pyutils.c +++ b/plugins/python/pyutils.c @@ -208,7 +208,12 @@ PyObject *python_call(PyObject *callable, PyObject *args, int catch, struct wsgi //uwsgi_log("called\n"); if (PyErr_Occurred()) { - uwsgi_manage_exception(wsgi_req, catch); + if (wsgi_req) { + uwsgi_manage_exception(wsgi_req, catch); + } + else { + PyErr_Print(); + } } #ifdef UWSGI_DEBUG diff --git a/uwsgidecorators.py b/uwsgidecorators.py index 89c1cc98..15b11cd8 100644 --- a/uwsgidecorators.py +++ b/uwsgidecorators.py @@ -1,4 +1,5 @@ import uwsgi +import sys from threading import Thread try: @@ -170,7 +171,12 @@ class mule_brain(object): def __call__(self): if uwsgi.mule_id() == self.num: - self.f() + try: + self.f() + except: + exc = sys.exc_info() + sys.excepthook(exc[0], exc[1], exc[2]) + sys.exit(1) class mule_brainloop(mule_brain): @@ -178,7 +184,12 @@ class mule_brainloop(mule_brain): def __call__(self): if uwsgi.mule_id() == self.num: while True: - self.f() + try: + self.f() + except: + exc = sys.exc_info() + sys.excepthook(exc[0], exc[1], exc[2]) + sys.exit(1) class mule(object):