Module: kamailio
Branch: master
Commit: de6cb088639340153f41fb6183a192b3dc4c4a8b
URL: 
https://github.com/kamailio/kamailio/commit/de6cb088639340153f41fb6183a192b3dc4c4a8b

Author: Daniel-Constantin Mierla <[email protected]>
Committer: Daniel-Constantin Mierla <[email protected]>
Date: 2016-04-27T20:36:34+02:00

app_python: handle python sys.exit() exception with dbg messages

- allow to use it for same purpose as exit in kamailio.cfg

---

Modified: modules/app_python/python_support.c

---

Diff:  
https://github.com/kamailio/kamailio/commit/de6cb088639340153f41fb6183a192b3dc4c4a8b.diff
Patch: 
https://github.com/kamailio/kamailio/commit/de6cb088639340153f41fb6183a192b3dc4c4a8b.patch

---

diff --git a/modules/app_python/python_support.c 
b/modules/app_python/python_support.c
index d19cd64..f5f0cdb 100644
--- a/modules/app_python/python_support.c
+++ b/modules/app_python/python_support.c
@@ -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())
@@ -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);
@@ -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);


_______________________________________________
sr-dev mailing list
[email protected]
http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-dev

Reply via email to