Skip to content

Commit

Permalink
app_python: handle python sys.exit() exception with dbg messages
Browse files Browse the repository at this point in the history
- allow to use it for same purpose as exit in kamailio.cfg
  • Loading branch information
miconda committed Apr 27, 2016
1 parent c7175f6 commit de6cb08
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions modules/app_python/python_support.c
Expand Up @@ -39,6 +39,7 @@ void python_handle_exception(const char *fmt, ...)
PyObject *line;
int i;
char *srcbuf;
int exc_exit = 0;

// We don't want to generate traceback when no errors occured
if (!PyErr_Occurred())
Expand All @@ -62,6 +63,7 @@ void python_handle_exception(const char *fmt, ...)
return;
}

exc_exit = PyErr_GivenExceptionMatches(exception, PyExc_SystemExit);
args = PyTuple_Pack(3, exception, v, tb ? tb : Py_None);
Py_XDECREF(exception);
Py_XDECREF(v);
Expand Down Expand Up @@ -127,10 +129,19 @@ void python_handle_exception(const char *fmt, ...)
Py_DECREF(line);
}

if (srcbuf == NULL)
LM_ERR("Unhandled exception in the Python code:\n%s", buf);
else
LM_ERR("%s: Unhandled exception in the Python code:\n%s", srcbuf, buf);
if (srcbuf == NULL) {
if(exc_exit) {
LM_DBG("Unhandled exception in the Python code:\n%s", buf);
} else {
LM_ERR("Unhandled exception in the Python code:\n%s", buf);
}
} else {
if(exc_exit) {
LM_DBG("%s: Unhandled exception in the Python code:\n%s", srcbuf, buf);
} else {
LM_ERR("%s: Unhandled exception in the Python code:\n%s", srcbuf, buf);
}
}

if (buf)
pkg_free(buf);
Expand Down

0 comments on commit de6cb08

Please sign in to comment.