summaryrefslogtreecommitdiffhomepage
path: root/src/python/nxt_python.c
diff options
context:
space:
mode:
authorMax Romanov <max.romanov@nginx.com>2020-10-01 23:55:23 +0300
committerMax Romanov <max.romanov@nginx.com>2020-10-01 23:55:23 +0300
commitc4c2f90c5b532c1ec283d211e0fd50e4538c2a51 (patch)
tree2fc2558bc370d80f5d60a0d6c5a0c6791a48e466 /src/python/nxt_python.c
parentbbc6d2470afe8bfc8a97427b0b576080466bd31a (diff)
downloadunit-c4c2f90c5b532c1ec283d211e0fd50e4538c2a51.tar.gz
unit-c4c2f90c5b532c1ec283d211e0fd50e4538c2a51.tar.bz2
Python: ASGI server introduced.
This closes #461 issue on GitHub.
Diffstat (limited to 'src/python/nxt_python.c')
-rw-r--r--src/python/nxt_python.c28
1 files changed, 17 insertions, 11 deletions
diff --git a/src/python/nxt_python.c b/src/python/nxt_python.c
index 7d4589ed..01534a47 100644
--- a/src/python/nxt_python.c
+++ b/src/python/nxt_python.c
@@ -15,14 +15,6 @@
#include NXT_PYTHON_MOUNTS_H
-#if PY_MAJOR_VERSION == 3
-#define PyString_FromStringAndSize(str, size) \
- PyUnicode_DecodeLatin1((str), (size), "strict")
-
-#else
-#define PyUnicode_InternInPlace PyString_InternInPlace
-#endif
-
static nxt_int_t nxt_python_start(nxt_task_t *task,
nxt_process_data_t *data);
static void nxt_python_atexit(void);
@@ -56,7 +48,7 @@ static char *nxt_py_home;
static nxt_int_t
nxt_python_start(nxt_task_t *task, nxt_process_data_t *data)
{
- int rc;
+ int rc, asgi;
char *nxt_py_module;
size_t len;
PyObject *obj, *pypath, *module;
@@ -226,7 +218,15 @@ nxt_python_start(nxt_task_t *task, nxt_process_data_t *data)
python_init.shm_limit = data->app->shm_limit;
- rc = nxt_python_wsgi_init(task, &python_init);
+ asgi = nxt_python_asgi_check(nxt_py_application);
+
+ if (asgi) {
+ rc = nxt_python_asgi_init(task, &python_init);
+
+ } else {
+ rc = nxt_python_wsgi_init(task, &python_init);
+ }
+
if (nxt_slow_path(rc == NXT_ERROR)) {
goto fail;
}
@@ -236,7 +236,12 @@ nxt_python_start(nxt_task_t *task, nxt_process_data_t *data)
goto fail;
}
- rc = nxt_python_wsgi_run(unit_ctx);
+ if (asgi) {
+ rc = nxt_python_asgi_run(unit_ctx);
+
+ } else {
+ rc = nxt_python_wsgi_run(unit_ctx);
+ }
nxt_unit_done(unit_ctx);
@@ -300,6 +305,7 @@ static void
nxt_python_atexit(void)
{
nxt_python_wsgi_done();
+ nxt_python_asgi_done();
Py_XDECREF(nxt_py_stderr_flush);
Py_XDECREF(nxt_py_application);