Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Drop Python ~3.2 #2620

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
runs-on: ubuntu-20.04
strategy:
matrix:
python-version: ["2.7", "3.6", "3.7", "3.8", "3.9", "3.10", "3.11", "3.12"]
python-version: ["3.6", "3.7", "3.8", "3.9", "3.10", "3.11", "3.12"]
test-suite: [unittest, python, deadlocks]
steps:
- name: Add deadnakes ppa
Expand Down
12 changes: 4 additions & 8 deletions plugins/asyncio/asyncio.c
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ static PyObject *py_uwsgi_asyncio_request(PyObject *self, PyObject *args) {

end:
uwsgi.async_proto_fd_table[wsgi_req->fd] = NULL;
uwsgi_close_request(uwsgi.wsgi_req);
uwsgi_close_request(uwsgi.wsgi_req);
free_req_queue;
again:
Py_INCREF(Py_None);
Expand Down Expand Up @@ -282,11 +282,11 @@ static void uwsgi_asyncio_schedule_fix(struct wsgi_request *wsgi_req) {
PyObject *cb = PyObject_CallMethod(uasyncio.loop, "call_soon", "Ol", uasyncio.hook_fix, (long) wsgi_req);
if (!cb) goto error;
Py_DECREF(cb);
return;
return;

error:
PyErr_Print();
}
}

static void asyncio_loop() {

Expand Down Expand Up @@ -328,11 +328,7 @@ static void asyncio_loop() {
uwsgi.schedule_fix = uwsgi_asyncio_schedule_fix;
}

#ifndef PYTHREE
PyObject *asyncio = PyImport_ImportModule("trollius");
#else
PyObject *asyncio = PyImport_ImportModule("asyncio");
#endif
if (!asyncio) uwsgi_pyexit;

uasyncio.mod = asyncio;
Expand Down Expand Up @@ -366,7 +362,7 @@ static void asyncio_loop() {
uwsgi_pyexit;
}
uwsgi_sock = uwsgi_sock->next;
}
}

if (PyObject_CallMethod(uasyncio.loop, "run_forever", NULL) == NULL) {
uwsgi_pyexit;
Expand Down
11 changes: 0 additions & 11 deletions plugins/python/gil.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,14 @@ extern struct uwsgi_python up;

void gil_real_get() {
//uwsgi_log("LOCK %d\n", uwsgi.mywid);
#if !defined(PYTHREE)
PyEval_AcquireLock();
PyThreadState_Swap((PyThreadState *) pthread_getspecific(up.upt_gil_key));
#else
PyEval_RestoreThread((PyThreadState *) pthread_getspecific(up.upt_gil_key));
#endif

//uwsgi_log("LOCKED !!! %d\n", uwsgi.mywid);
}

void gil_real_release() {
//uwsgi_log("UNLOCK %d\n", uwsgi.mywid);
#if !defined(PYTHREE)
pthread_setspecific(up.upt_gil_key, (void *) PyThreadState_Swap(NULL));
PyEval_ReleaseLock();
#else
pthread_setspecific(up.upt_gil_key, (void *) PyThreadState_Get());
PyEval_SaveThread();
#endif
}


Expand Down
13 changes: 0 additions & 13 deletions plugins/python/profiler.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,6 @@

extern struct uwsgi_server uwsgi;

#ifdef HAS_NOT_PyFrame_GetLineNumber
int PyFrame_GetLineNumber(PyFrameObject *frame) {
if (frame->f_trace) {
return frame->f_lineno;
}
else {
return PyCode_Addr2Line(frame->f_code, frame->f_lasti);
}
}
#endif

#if PY_VERSION_HEX < 0x030900B1
PyCodeObject* PyFrame_GetCode(PyFrameObject *frame)
{
Expand All @@ -21,14 +10,12 @@ PyCodeObject* PyFrame_GetCode(PyFrameObject *frame)
}
#endif

#ifdef PYTHREE
#undef PyString_AsString
static char *PyString_AsString(PyObject *o) {
PyObject *zero = PyUnicode_AsLatin1String(o);
if (!zero) return "";
return PyBytes_AsString(zero);
}
#endif

int uwsgi_python_profiler_call(PyObject *obj, PyFrameObject *frame, int what, PyObject *arg) {

Expand Down
14 changes: 0 additions & 14 deletions plugins/python/pump_subhandler.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,8 @@ void *uwsgi_request_subhandler_pump(struct wsgi_request *wsgi_req, struct uwsgi_
if (wsgi_req->hvec[i].iov_len < 6) continue;
if (!uwsgi_startswith(wsgi_req->hvec[i].iov_base, "HTTP_", 5)) {
(void) uwsgi_lower(wsgi_req->hvec[i].iov_base+5, wsgi_req->hvec[i].iov_len-5);
#ifdef PYTHREE
pydictkey = PyUnicode_DecodeLatin1(wsgi_req->hvec[i].iov_base+5, wsgi_req->hvec[i].iov_len-5, NULL);
pydictvalue = PyUnicode_DecodeLatin1(wsgi_req->hvec[i + 1].iov_base, wsgi_req->hvec[i + 1].iov_len, NULL);
#else
pydictkey = PyString_FromStringAndSize(wsgi_req->hvec[i].iov_base+5, wsgi_req->hvec[i].iov_len-5);
pydictvalue = PyString_FromStringAndSize(wsgi_req->hvec[i + 1].iov_base, wsgi_req->hvec[i + 1].iov_len);
#endif
PyObject *old_value = PyDict_GetItem(headers, pydictkey);
if (old_value) {
if (PyString_Check(old_value)) {
Expand Down Expand Up @@ -199,11 +194,7 @@ int uwsgi_response_subhandler_pump(struct wsgi_request *wsgi_req) {
}

PyObject *hhkey, *hhvalue;
#ifdef UWSGI_PYTHON_OLD
int hhpos = 0;
#else
Py_ssize_t hhpos = 0;
#endif
while (PyDict_Next(headers, &hhpos, &hhkey, &hhvalue)) {
if (!PyString_Check(hhkey)) continue;

Expand Down Expand Up @@ -235,12 +226,7 @@ int uwsgi_response_subhandler_pump(struct wsgi_request *wsgi_req) {
}
goto clear;
}
#ifdef PYTHREE
else if ((wsgi_req->sendfile_fd = PyObject_AsFileDescriptor((PyObject *)wsgi_req->async_placeholder)) > -1) {
#else
else if (PyFile_Check((PyObject *)wsgi_req->async_placeholder)) {
wsgi_req->sendfile_fd = fileno(PyFile_AsFile((PyObject *)wsgi_req->async_placeholder));
#endif
UWSGI_RELEASE_GIL
uwsgi_response_sendfile_do(wsgi_req, wsgi_req->sendfile_fd, 0, 0);
UWSGI_GET_GIL
Expand Down
49 changes: 0 additions & 49 deletions plugins/python/python_plugin.c
Original file line number Diff line number Diff line change
Expand Up @@ -190,9 +190,7 @@ struct uwsgi_option uwsgi_python_options[] = {

{"python-raw", required_argument, 0, "load a python file for managing raw requests", uwsgi_opt_set_str, &up.raw, 0},

#if defined(PYTHREE) || defined(Py_TPFLAGS_HAVE_NEWBUFFER)
{"py-sharedarea", required_argument, 0, "create a sharedarea from a python bytearray object of the specified size", uwsgi_opt_add_string_list, &up.sharedarea, 0},
#endif

{"py-call-osafterfork", no_argument, 0, "enable child processes running cpython to trap OS signals", uwsgi_opt_true, &up.call_osafterfork, 0},
{"py-call-uwsgi-fork-hooks", no_argument, 0, "call pre and post hooks when uswgi forks to update the internal interpreter state of CPython", uwsgi_opt_true, &up.call_uwsgi_fork_hooks, 0},
Expand Down Expand Up @@ -235,7 +233,6 @@ PyMethodDef uwsgi_write_method[] = { {"uwsgi_write", py_uwsgi_write, METH_VARARG

PyDoc_STRVAR(uwsgi_py_doc, "uWSGI api module.");

#ifdef PYTHREE
static PyModuleDef uwsgi_module3 = {
PyModuleDef_HEAD_INIT,
"uwsgi",
Expand All @@ -246,7 +243,6 @@ static PyModuleDef uwsgi_module3 = {
PyObject *init_uwsgi3(void) {
return PyModule_Create(&uwsgi_module3);
}
#endif

int uwsgi_python_init() {

Expand All @@ -269,7 +265,6 @@ int uwsgi_python_init() {
uwsgi_log("Python Home is not a directory: %s\n", up.home);
exit(1);
}
#ifdef PYTHREE
// check for PEP 405 virtualenv (starting from python 3.3)
char *pep405_env = uwsgi_concat2(up.home, "/pyvenv.cfg");
if (uwsgi_file_exists(pep405_env)) {
Expand All @@ -292,9 +287,6 @@ int uwsgi_python_init() {
// do not free this memory !!!
//free(wpyhome);
pep405:
#else
Py_SetPythonHome(up.home);
#endif
uwsgi_log("Set PythonHome to %s\n", up.home);
}

Expand All @@ -303,7 +295,6 @@ int uwsgi_python_init() {
program_name = uwsgi.binary_path;
}

#ifdef PYTHREE
if (!up.programname) {
if (up.home) {
program_name = uwsgi_concat2(up.home, "/bin/python");
Expand All @@ -316,10 +307,6 @@ int uwsgi_python_init() {
#ifdef UWSGI_PY312
PyImport_AppendInittab("uwsgi", init_uwsgi3);
#endif
#else
Py_SetProgramName(program_name);
#endif


Py_OptimizeFlag = up.optimize;

Expand All @@ -343,7 +330,6 @@ int uwsgi_python_init() {
up.swap_ts = simple_swap_ts;
up.reset_ts = simple_reset_ts;

#if defined(PYTHREE) || defined(Py_TPFLAGS_HAVE_NEWBUFFER)
struct uwsgi_string_list *usl = NULL;
uwsgi_foreach(usl, up.sharedarea) {
uint64_t len = uwsgi_n64(usl->value);
Expand All @@ -353,7 +339,6 @@ int uwsgi_python_init() {
struct uwsgi_sharedarea *sa = uwsgi_sharedarea_init_ptr(storage, len);
sa->obj = obj;
}
#endif

uwsgi_log_initial("Python main interpreter initialized at %p\n", up.main_thread);

Expand Down Expand Up @@ -597,7 +582,6 @@ void init_uwsgi_vars() {
}
pysys_dict = PyModule_GetDict(pysys);

#ifdef PYTHREE
// In python3, stdout / stderr was changed to be buffered (a bug according
// to many):
// - https://bugs.python.org/issue13597
Expand All @@ -606,17 +590,12 @@ void init_uwsgi_vars() {
// In the case of a tty, this fix breaks readline support in interactive
// debuggers so we'll only do this in the non-tty case.
if (!Py_FdIsInteractive(stdin, NULL)) {
#ifdef HAS_NO_ERRORS_IN_PyFile_FromFd
PyObject *new_stdprint = PyFile_FromFd(2, NULL, "w", _IOLBF, NULL, NULL, 0);
#else
PyObject *new_stdprint = PyFile_FromFd(2, NULL, "w", _IOLBF, NULL, "backslashreplace", NULL, 0);
#endif
PyDict_SetItemString(pysys_dict, "stdout", new_stdprint);
PyDict_SetItemString(pysys_dict, "__stdout__", new_stdprint);
PyDict_SetItemString(pysys_dict, "stderr", new_stdprint);
PyDict_SetItemString(pysys_dict, "__stderr__", new_stdprint);
}
#endif
pypath = PyDict_GetItemString(pysys_dict, "path");
if (!pypath) {
PyErr_Print();
Expand Down Expand Up @@ -697,14 +676,10 @@ void init_uwsgi_embedded_module() {
}


#ifdef PYTHREE
#ifndef UWSGI_PY312
PyImport_AppendInittab("uwsgi", init_uwsgi3);
#endif
new_uwsgi_module = PyImport_AddModule("uwsgi");
#else
new_uwsgi_module = Py_InitModule3("uwsgi", NULL, uwsgi_py_doc);
#endif
if (new_uwsgi_module == NULL) {
uwsgi_log("could not initialize the uwsgi python module\n");
exit(1);
Expand Down Expand Up @@ -827,11 +802,7 @@ void init_uwsgi_embedded_module() {

PyObject *py_opt_dict = PyDict_New();
for (i = 0; i < uwsgi.exported_opts_cnt; i++) {
#ifdef PYTHREE
PyObject *key = PyUnicode_FromString(uwsgi.exported_opts[i]->key);
#else
PyObject *key = PyString_FromString(uwsgi.exported_opts[i]->key);
#endif
if (PyDict_Contains(py_opt_dict, key)) {
PyObject *py_opt_item = PyDict_GetItem(py_opt_dict, key);
if (PyList_Check(py_opt_item)) {
Expand Down Expand Up @@ -1458,11 +1429,7 @@ void uwsgi_python_set_thread_name(int core_id) {
PyErr_Clear();
}
else {
#ifdef PYTHREE
PyObject_SetAttrString(current_thread, "name", PyUnicode_FromFormat("uWSGIWorker%dCore%d", uwsgi.mywid, core_id));
#else
PyObject_SetAttrString(current_thread, "name", PyString_FromFormat("uWSGIWorker%dCore%d", uwsgi.mywid, core_id));
#endif
Py_INCREF(current_thread);
}
}
Expand Down Expand Up @@ -1577,11 +1544,7 @@ void *uwsgi_python_autoreloader_thread(void *interpreter) {
// do not start monitoring til the first app is loaded (required for lazy mode)
if (uwsgi_apps_cnt == 0) continue;
}
#ifdef UWSGI_PYTHON_OLD
int pos = 0;
#else
Py_ssize_t pos = 0;
#endif
char *app_dir = NULL;
int i;
for (i = 0; i < uwsgi_apps_cnt; i++) {
Expand All @@ -1597,15 +1560,11 @@ void *uwsgi_python_autoreloader_thread(void *interpreter) {
int found = 0;
struct uwsgi_string_list *usl = up.auto_reload_ignore;
while(usl) {
#ifdef PYTHREE
PyObject *zero = PyUnicode_AsUTF8String(mod_name);
char *str_mod_name = PyString_AsString(zero);
int ret_cmp = strcmp(usl->value, str_mod_name);
Py_DECREF(zero);
if (!ret_cmp) {
#else
if (!strcmp(usl->value, PyString_AsString(mod_name))) {
#endif
found = 1;
break;
}
Expand All @@ -1616,16 +1575,10 @@ void *uwsgi_python_autoreloader_thread(void *interpreter) {
PyObject *mod_file = PyObject_GetAttrString(mod, "__file__");
if (!mod_file) continue;
if (mod_file == Py_None) continue;
#ifdef PYTHREE
PyObject *zero = PyUnicode_AsUTF8String(mod_file);
char *mod_filename = PyString_AsString(zero);
#else
char *mod_filename = PyString_AsString(mod_file);
#endif
if (!mod_filename) {
#ifdef PYTHREE
Py_DECREF(zero);
#endif
continue;
}
char *ext = strrchr(mod_filename, '.');
Expand All @@ -1645,9 +1598,7 @@ void *uwsgi_python_autoreloader_thread(void *interpreter) {
return NULL;
}
free(filename);
#ifdef PYTHREE
Py_DECREF(zero);
#endif
}
}

Expand Down
Loading