Skip to content

Commit

Permalink
resolve pull reqeuest discussions
Browse files Browse the repository at this point in the history
  • Loading branch information
StanislavMitrofanov committed Jan 17, 2023
1 parent 3cb131b commit c545a4c
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 52 deletions.
4 changes: 2 additions & 2 deletions src/python/nxt_python.c
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ nxt_python_start(nxt_task_t *task, nxt_process_data_t *data)
goto fail;
}

rc = nxt_py_proto.ctx_data_alloc(&python_init.ctx_data, 1);
rc = nxt_py_proto.ctx_data_alloc(&python_init.ctx_data);
if (nxt_slow_path(rc != NXT_UNIT_OK)) {
goto fail;
}
Expand Down Expand Up @@ -623,7 +623,7 @@ nxt_python_init_threads(nxt_python_app_conf_t *c)
for (i = 0; i < c->threads - 1; i++) {
ti = &nxt_py_threads[i];

res = nxt_py_proto.ctx_data_alloc(&ti->ctx_data, 0);
res = nxt_py_proto.ctx_data_alloc(&ti->ctx_data);
if (nxt_slow_path(res != NXT_UNIT_OK)) {
return NXT_UNIT_ERROR;
}
Expand Down
2 changes: 1 addition & 1 deletion src/python/nxt_python.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ typedef struct {


typedef struct {
int (*ctx_data_alloc)(void **pdata, int main);
int (*ctx_data_alloc)(void **pdata);
void (*ctx_data_free)(void *data);
int (*startup)(void *data);
int (*run)(nxt_unit_ctx_t *ctx);
Expand Down
44 changes: 12 additions & 32 deletions src/python/nxt_python_asgi.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@


static PyObject *nxt_python_asgi_get_func(PyObject *obj);
static int nxt_python_asgi_ctx_data_alloc(void **pdata, int main);
static int nxt_python_asgi_ctx_data_alloc(void **pdata);
static void nxt_python_asgi_ctx_data_free(void *data);
static int nxt_python_asgi_startup(void *data);
static int nxt_python_asgi_run(nxt_unit_ctx_t *ctx);
Expand Down Expand Up @@ -199,9 +199,9 @@ nxt_python_asgi_init(nxt_unit_init_t *init, nxt_python_proto_t *proto)

return NXT_UNIT_OK;
}
#if NXT_HAVE_ASYNCIO_RUNNER
#if (NXT_HAVE_ASYNCIO_RUNNER)
static int
nxt_python_asgi_ctx_data_alloc(void **pdata, int main)
nxt_python_asgi_ctx_data_alloc(void **pdata)
{
uint32_t i;
PyObject *asyncio, *loop, *obj, *runner_ref, *runner, *loop_ref;
Expand Down Expand Up @@ -322,33 +322,10 @@ nxt_python_asgi_ctx_data_alloc(void **pdata, int main)
return NXT_UNIT_ERROR;
}


static void
nxt_python_asgi_ctx_data_free(void *data)
{
nxt_py_asgi_ctx_data_t *ctx_data;
PyObject *close_loop_func;

ctx_data = data;

Py_XDECREF(ctx_data->loop_run_until_complete);
Py_XDECREF(ctx_data->loop_create_future);
Py_XDECREF(ctx_data->loop_create_task);
Py_XDECREF(ctx_data->loop_call_soon);
Py_XDECREF(ctx_data->loop_add_reader);
Py_XDECREF(ctx_data->loop_remove_reader);
Py_XDECREF(ctx_data->quit_future);
Py_XDECREF(ctx_data->quit_future_set_result);
close_loop_func = PyObject_GetAttrString(ctx_data->runner, "close");
PyObject_CallObject(close_loop_func, NULL);
Py_XDECREF(ctx_data->runner);

nxt_unit_free(NULL, ctx_data);
}
#else

static int
nxt_python_asgi_ctx_data_alloc(void **pdata, int main)
nxt_python_asgi_ctx_data_alloc(void **pdata)
{
uint32_t i;
PyObject *asyncio, *loop, *event_loop, *obj;
Expand Down Expand Up @@ -387,7 +364,7 @@ nxt_python_asgi_ctx_data_alloc(void **pdata, int main)
goto fail;
}

event_loop_func = main ? "get_event_loop" : "new_event_loop";
event_loop_func = "new_event_loop";

event_loop = PyDict_GetItemString(PyModule_GetDict(asyncio),
event_loop_func);
Expand Down Expand Up @@ -467,7 +444,7 @@ nxt_python_asgi_ctx_data_alloc(void **pdata, int main)

return NXT_UNIT_ERROR;
}

#endif

static void
nxt_python_asgi_ctx_data_free(void *data)
Expand All @@ -484,11 +461,14 @@ nxt_python_asgi_ctx_data_free(void *data)
Py_XDECREF(ctx_data->loop_remove_reader);
Py_XDECREF(ctx_data->quit_future);
Py_XDECREF(ctx_data->quit_future_set_result);

#if (NXT_HAVE_ASYNCIO_RUNNER)
PyObject *close_loop_func;
close_loop_func = PyObject_GetAttrString(ctx_data->runner, "close");
PyObject_CallObject(close_loop_func, NULL);
Py_XDECREF(ctx_data->runner);
#endif
nxt_unit_free(NULL, ctx_data);
}
#endif



static int
Expand Down
19 changes: 4 additions & 15 deletions src/python/nxt_python_asgi.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ typedef struct {
nxt_unit_request_info_t *req;
uint64_t content_length;
} nxt_py_asgi_add_field_ctx_t;
#ifdef NXT_HAVE_ASYNCIO_RUNNER

typedef struct {
nxt_queue_t drain_queue;
PyObject *loop_run_until_complete;
Expand All @@ -34,22 +34,11 @@ typedef struct {
PyObject *quit_future;
PyObject *quit_future_set_result;
PyObject **target_lifespans;
#if (NXT_HAVE_ASYNCIO_RUNNER)
PyObject *runner;
#endif
} nxt_py_asgi_ctx_data_t;
#else
typedef struct {
nxt_queue_t drain_queue;
PyObject *loop_run_until_complete;
PyObject *loop_create_future;
PyObject *loop_create_task;
PyObject *loop_call_soon;
PyObject *loop_add_reader;
PyObject *loop_remove_reader;
PyObject *quit_future;
PyObject *quit_future_set_result;
PyObject **target_lifespans;
} nxt_py_asgi_ctx_data_t;
#endif


PyObject *nxt_py_asgi_enum_headers(PyObject *headers,
nxt_py_asgi_enum_header_cb cb, void *data);
Expand Down
4 changes: 2 additions & 2 deletions src/python/nxt_python_wsgi.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ typedef struct {
} nxt_python_ctx_t;


static int nxt_python_wsgi_ctx_data_alloc(void **pdata, int main);
static int nxt_python_wsgi_ctx_data_alloc(void **pdata);
static void nxt_python_wsgi_ctx_data_free(void *data);
static int nxt_python_wsgi_run(nxt_unit_ctx_t *ctx);
static void nxt_python_wsgi_done(void);
Expand Down Expand Up @@ -217,7 +217,7 @@ nxt_python_wsgi_init(nxt_unit_init_t *init, nxt_python_proto_t *proto)


static int
nxt_python_wsgi_ctx_data_alloc(void **pdata, int main)
nxt_python_wsgi_ctx_data_alloc(void **pdata)
{
nxt_python_ctx_t *pctx;

Expand Down

0 comments on commit c545a4c

Please sign in to comment.