summaryrefslogtreecommitdiffhomepage
path: root/src/nxt_python_wsgi.c
diff options
context:
space:
mode:
authorMax Romanov <max.romanov@nginx.com>2017-12-27 14:02:11 +0300
committerMax Romanov <max.romanov@nginx.com>2017-12-27 14:02:11 +0300
commitbe36cf52c8b092ebb688784a1c10626cac2138d7 (patch)
treec7b725425e12be5d8aa04114c3436f78726b1db1 /src/nxt_python_wsgi.c
parentcdfdbc43eb2f6c59bf1b1cf6d71a6afec34d7869 (diff)
downloadunit-be36cf52c8b092ebb688784a1c10626cac2138d7.tar.gz
unit-be36cf52c8b092ebb688784a1c10626cac2138d7.tar.bz2
Introducing application 'atexit' hook.
Finalizing Python interpreter. This closes #65 issue on GitHub.
Diffstat (limited to '')
-rw-r--r--src/nxt_python_wsgi.c18
1 files changed, 17 insertions, 1 deletions
diff --git a/src/nxt_python_wsgi.c b/src/nxt_python_wsgi.c
index 36cd8e14..0f56ea37 100644
--- a/src/nxt_python_wsgi.c
+++ b/src/nxt_python_wsgi.c
@@ -60,9 +60,9 @@ typedef struct {
typedef struct nxt_python_run_ctx_s nxt_python_run_ctx_t;
static nxt_int_t nxt_python_init(nxt_task_t *task, nxt_common_app_conf_t *conf);
-
static nxt_int_t nxt_python_run(nxt_task_t *task,
nxt_app_rmsg_t *rmsg, nxt_app_wmsg_t *msg);
+static void nxt_python_atexit(nxt_task_t *task);
static PyObject *nxt_python_create_environ(nxt_task_t *task);
static PyObject *nxt_python_get_environ(nxt_task_t *task,
@@ -103,6 +103,7 @@ NXT_EXPORT nxt_application_module_t nxt_app_module = {
nxt_string(PY_VERSION),
nxt_python_init,
nxt_python_run,
+ nxt_python_atexit,
};
@@ -455,6 +456,21 @@ fail:
}
+static void
+nxt_python_atexit(nxt_task_t *task)
+{
+ Py_DECREF(nxt_py_application);
+ Py_DECREF(nxt_py_start_resp_obj);
+ Py_DECREF(nxt_py_environ_ptyp);
+
+ Py_Finalize();
+
+ if (nxt_py_home != NULL) {
+ nxt_free(nxt_py_home);
+ }
+}
+
+
static PyObject *
nxt_python_create_environ(nxt_task_t *task)
{