diff options
author | Valentin Bartenev <vbart@nginx.com> | 2018-12-20 15:47:10 +0300 |
---|---|---|
committer | Valentin Bartenev <vbart@nginx.com> | 2018-12-20 15:47:10 +0300 |
commit | 27394118b32ab395be50de15ecf514d5529090c5 (patch) | |
tree | 90952281b51df8384d2c69743f48665717cb5af1 | |
parent | 1ce7e860b2913bc5c89258dca6c8fa9cf86ade35 (diff) | |
download | unit-27394118b32ab395be50de15ecf514d5529090c5.tar.gz unit-27394118b32ab395be50de15ecf514d5529090c5.tar.bz2 |
Python: fixed error reporting on initialization of applications.
PyErr_Print() writes traceback to "sys.stderr", which is a file object that
can buffer the output. If the process exits immediately, the buffer can be
destroyed before flushing to the log. As a result, the user doesn't see
the traceback.
Now Py_Finalize() is also called in case of any errors during initialization.
It finalizes the interpreter and flushes all data.
Diffstat (limited to '')
-rw-r--r-- | src/nxt_python_wsgi.c | 21 |
1 files changed, 10 insertions, 11 deletions
diff --git a/src/nxt_python_wsgi.c b/src/nxt_python_wsgi.c index b6566788..bd3a2cb2 100644 --- a/src/nxt_python_wsgi.c +++ b/src/nxt_python_wsgi.c @@ -339,7 +339,7 @@ nxt_python_init(nxt_task_t *task, nxt_common_app_conf_t *conf) goto fail; } - Py_DECREF(obj); + Py_CLEAR(obj); nxt_py_module = nxt_alloca(c->module.length + 1); nxt_memcpy(nxt_py_module, c->module.start, c->module.length); @@ -349,7 +349,7 @@ nxt_python_init(nxt_task_t *task, nxt_common_app_conf_t *conf) if (nxt_slow_path(module == NULL)) { nxt_alert(task, "Python failed to import module \"%s\"", nxt_py_module); PyErr_Print(); - return NXT_ERROR; + goto fail; } obj = PyDict_GetItemString(PyModule_GetDict(module), "application"); @@ -367,9 +367,10 @@ nxt_python_init(nxt_task_t *task, nxt_common_app_conf_t *conf) } Py_INCREF(obj); - Py_DECREF(module); + Py_CLEAR(module); nxt_py_application = obj; + obj = NULL; nxt_unit_default_init(task, &python_init); @@ -377,7 +378,7 @@ nxt_python_init(nxt_task_t *task, nxt_common_app_conf_t *conf) unit_ctx = nxt_unit_init(&python_init); if (nxt_slow_path(unit_ctx == NULL)) { - return NXT_ERROR; + goto fail; } rc = nxt_unit_run(unit_ctx); @@ -395,9 +396,7 @@ fail: Py_XDECREF(obj); Py_XDECREF(module); - if (nxt_py_home != NULL) { - nxt_free(nxt_py_home); - } + nxt_python_atexit(); return NXT_ERROR; } @@ -529,10 +528,10 @@ fail: static void nxt_python_atexit(void) { - Py_DECREF(nxt_py_application); - Py_DECREF(nxt_py_start_resp_obj); - Py_DECREF(nxt_py_write_obj); - Py_DECREF(nxt_py_environ_ptyp); + Py_XDECREF(nxt_py_application); + Py_XDECREF(nxt_py_start_resp_obj); + Py_XDECREF(nxt_py_write_obj); + Py_XDECREF(nxt_py_environ_ptyp); Py_Finalize(); |