فهرست منبع

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

- allow to use it for same purpose as exit in kamailio.cfg
Daniel-Constantin Mierla 9 سال پیش
والد
کامیت
de6cb08863
1فایلهای تغییر یافته به همراه15 افزوده شده و 4 حذف شده
  1. 15 4
      modules/app_python/python_support.c

+ 15 - 4
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);