1
1
/* ------------------------------------------------------------------------- */
2
2
3
3
/*
4
- * Copyright 2007-2021 GRAHAM DUMPLETON
4
+ * Copyright 2007-2022 GRAHAM DUMPLETON
5
5
*
6
6
* Licensed under the Apache License, Version 2.0 (the "License");
7
7
* you may not use this file except in compliance with the License.
@@ -4306,6 +4306,11 @@ static apr_status_t wsgi_python_child_cleanup(void *data)
4306
4306
wsgi_publish_process_stopping(wsgi_shutdown_reason);
4307
4307
#endif
4308
4308
4309
+ /* Skip destruction of Python interpreter. */
4310
+
4311
+ if (wsgi_server_config->destroy_interpreter == 0)
4312
+ return APR_SUCCESS;
4313
+
4309
4314
/* In a multithreaded MPM must protect table. */
4310
4315
4311
4316
#if APR_HAS_THREADS
@@ -5043,6 +5048,28 @@ static const char *wsgi_set_python_hash_seed(cmd_parms *cmd, void *mconfig,
5043
5048
return NULL;
5044
5049
}
5045
5050
5051
+ static const char *wsgi_set_destroy_interpreter(cmd_parms *cmd, void *mconfig,
5052
+ const char *f)
5053
+ {
5054
+ const char *error = NULL;
5055
+ WSGIServerConfig *sconfig = NULL;
5056
+
5057
+ error = ap_check_cmd_context(cmd, GLOBAL_ONLY);
5058
+ if (error != NULL)
5059
+ return error;
5060
+
5061
+ sconfig = ap_get_module_config(cmd->server->module_config, &wsgi_module);
5062
+
5063
+ if (strcasecmp(f, "Off") == 0)
5064
+ sconfig->destroy_interpreter = 0;
5065
+ else if (strcasecmp(f, "On") == 0)
5066
+ sconfig->destroy_interpreter = 1;
5067
+ else
5068
+ return "WSGIDestroyInterpreter must be one of: Off | On";
5069
+
5070
+ return NULL;
5071
+ }
5072
+
5046
5073
static const char *wsgi_set_restrict_embedded(cmd_parms *cmd, void *mconfig,
5047
5074
const char *f)
5048
5075
{
@@ -9521,17 +9548,26 @@ static void wsgi_log_stack_traces(void)
9521
9548
const char *filename = NULL;
9522
9549
const char *name = NULL;
9523
9550
9551
+ #if PY_MAJOR_VERSION > 3 || (PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION >= 9)
9552
+ lineno = PyFrame_GetLineNumber(current);
9553
+ #else
9524
9554
if (current->f_trace) {
9525
9555
lineno = current->f_lineno;
9526
9556
}
9527
9557
else {
9528
9558
lineno = PyCode_Addr2Line(current->f_code,
9529
9559
current->f_lasti);
9530
9560
}
9561
+ #endif
9531
9562
9532
9563
#if PY_MAJOR_VERSION >= 3
9564
+ #if PY_MAJOR_VERSION > 3 || (PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION >= 9)
9565
+ filename = PyUnicode_AsUTF8(PyFrame_GetCode(current)->co_filename);
9566
+ name = PyUnicode_AsUTF8(PyFrame_GetCode(current)->co_name);
9567
+ #else
9533
9568
filename = PyUnicode_AsUTF8(current->f_code->co_filename);
9534
9569
name = PyUnicode_AsUTF8(current->f_code->co_name);
9570
+ #endif
9535
9571
#else
9536
9572
filename = PyString_AsString(current->f_code->co_filename);
9537
9573
name = PyString_AsString(current->f_code->co_name);
@@ -9544,7 +9580,11 @@ static void wsgi_log_stack_traces(void)
9544
9580
getpid(), thread_id, filename, lineno, name);
9545
9581
}
9546
9582
else {
9583
+ #if PY_MAJOR_VERSION > 3 || (PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION >= 9)
9584
+ if (PyFrame_GetBack(current)) {
9585
+ #else
9547
9586
if (current->f_back) {
9587
+ #endif
9548
9588
ap_log_error(APLOG_MARK, APLOG_INFO, 0, wsgi_server,
9549
9589
"mod_wsgi (pid=%d): called from file "
9550
9590
"\"%s\", line %d, in %s,", getpid(),
@@ -9558,7 +9598,11 @@ static void wsgi_log_stack_traces(void)
9558
9598
}
9559
9599
}
9560
9600
9601
+ #if PY_MAJOR_VERSION > 3 || (PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION >= 9)
9602
+ current = PyFrame_GetBack(current);
9603
+ #else
9561
9604
current = current->f_back;
9605
+ #endif
9562
9606
}
9563
9607
}
9564
9608
}
@@ -10011,7 +10055,7 @@ static int wsgi_start_process(apr_pool_t *p, WSGIDaemonProcess *daemon)
10011
10055
10012
10056
if (status != APR_SUCCESS) {
10013
10057
ap_log_error(APLOG_MARK, APLOG_CRIT, 0, wsgi_server,
10014
- "mod_wsgi (pid=%d): Couldn't intialise accept "
10058
+ "mod_wsgi (pid=%d): Couldn't initialise accept "
10015
10059
"mutex in daemon process '%s'.",
10016
10060
getpid(), daemon->group->mutex_path);
10017
10061
@@ -16224,6 +16268,9 @@ static const command_rec wsgi_commands[] =
16224
16268
AP_INIT_TAKE1("WSGIPythonHashSeed", wsgi_set_python_hash_seed,
16225
16269
NULL, RSRC_CONF, "Python hash seed."),
16226
16270
16271
+ AP_INIT_TAKE1("WSGIDestroyInterpreter", wsgi_set_destroy_interpreter,
16272
+ NULL, RSRC_CONF, "Enable/Disable destruction of Python interpreter."),
16273
+
16227
16274
#if defined(MOD_WSGI_WITH_DAEMONS)
16228
16275
AP_INIT_TAKE1("WSGIRestrictEmbedded", wsgi_set_restrict_embedded,
16229
16276
NULL, RSRC_CONF, "Enable/Disable use of embedded mode."),
0 commit comments