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

Add Python 3.11 support #2453

Merged
merged 1 commit into from
Jul 30, 2022
Merged

Add Python 3.11 support #2453

merged 1 commit into from
Jul 30, 2022

Conversation

vstinner
Copy link
Contributor

  • Use PyFrame_GetCode().
  • Add PyFrame_GetCode() for Python 3.8 and older.
  • Add UWSGI_PY311 macro: defined on Python 3.11 and newer.
  • struct uwsgi_python: "current_recursion_depth" becomes
    "current_recursion_remaining" and current_frame type becomes
    _PyCFrame** on Python 3.11.

Related Python 3.11 changes:

  • https://docs.python.org/dev/whatsnew/3.11.html#id6
  • The PyFrameObject structure became opaque.
  • PyThreadState.frame (PyFrameObject) became PyThreadState.cframe
    (_PyCFrame) in Python 3.11.
  • PyThreadState: recursion_depth was replaced with
    recursion_remaining + recursion_limit.

@vstinner
Copy link
Contributor Author

So far, I only checked that uwsgi builds successfully on Python 3.11 :-)

@vstinner
Copy link
Contributor Author

Fedora issue about uwsgi build issue with Python 3.11: https://bugzilla.redhat.com/show_bug.cgi?id=2099185

* Use PyFrame_GetCode().
* Add PyFrame_GetCode() for Python 3.8 and older.
* Add UWSGI_PY311 macro: defined on Python 3.11 and newer.
* struct uwsgi_python: "current_recursion_depth" becomes
  "current_recursion_remaining" and current_frame type becomes
  _PyCFrame** on Python 3.11.

Related Python 3.11 changes:

* https://docs.python.org/dev/whatsnew/3.11.html#id6
* The PyFrameObject structure became opaque.
* PyThreadState.frame (PyFrameObject) became PyThreadState.cframe
  (_PyCFrame) in Python 3.11.
* PyThreadState: recursion_depth was replaced with
  recursion_remaining + recursion_limit.
@vstinner
Copy link
Contributor Author

By the way, it would be nice to adapt plugins/python/python_plugin.c to the PyConfig API (PEP 587), to replace deprecated functions: https://docs.python.org/dev/c-api/init_config.html

############## end of uWSGI configuration #############
total build time: 44 seconds
*** uWSGI is ready, launch it with ./uwsgi ***
+ CFLAGS='-O2 -flto=auto -ffat-lto-objects -fexceptions -g -grecord-gcc-switches -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -fstack-protector-strong -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1  -m64  -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -Wno-unused-but-set-variable'
+ /usr/bin/python3 uwsgiconfig.py --verbose --plugin plugins/python fedora python3
plugins/python/python_plugin.c: In function ‘uwsgi_python_init’:
plugins/python/python_plugin.c:238:17: warning: ‘Py_SetPythonHome’ is deprecated [-Wdeprecated-declarations]
  238 |                 Py_SetPythonHome(wpyhome);
      |                 ^~~~~~~~~~~~~~~~
In file included from /usr/include/python3.11/Python.h:94,
                 from plugins/python/uwsgi_python.h:6,
                 from plugins/python/python_plugin.c:1:
/usr/include/python3.11/pylifecycle.h:40:38: note: declared here
   40 | Py_DEPRECATED(3.11) PyAPI_FUNC(void) Py_SetPythonHome(const wchar_t *);
      |                                      ^~~~~~~~~~~~~~~~
plugins/python/python_plugin.c:262:9: warning: ‘Py_SetProgramName’ is deprecated [-Wdeprecated-declarations]
  262 |         Py_SetProgramName(pname);
      |         ^~~~~~~~~~~~~~~~~
/usr/include/python3.11/pylifecycle.h:37:38: note: declared here
   37 | Py_DEPRECATED(3.11) PyAPI_FUNC(void) Py_SetProgramName(const wchar_t *);
      |                                      ^~~~~~~~~~~~~~~~~
plugins/python/pyutils.c: In function ‘init_pyargv’:
plugins/python/pyutils.c:391:9: warning: ‘PySys_SetArgv’ is deprecated [-Wdeprecated-declarations]
  391 |         PySys_SetArgv(up.argc, up.py_argv);
      |         ^~~~~~~~~~~~~
In file included from /usr/include/python3.11/Python.h:96,
                 from plugins/python/uwsgi_python.h:6,
                 from plugins/python/pyutils.c:1:
/usr/include/python3.11/sysmodule.h:13:38: note: declared here
   13 | Py_DEPRECATED(3.11) PyAPI_FUNC(void) PySys_SetArgv(int, wchar_t **);
      |                                      ^~~~~~~~~~~~~

@@ -13,6 +13,14 @@ int PyFrame_GetLineNumber(PyFrameObject *frame) {
}
#endif

#if PY_VERSION_HEX < 0x030900B1
PyCodeObject* PyFrame_GetCode(PyFrameObject *frame)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using https://github.com/python/pythoncapi-compat/ here would be interesting here, but I tried to mimick the coding style of the existing uwsgi code.

I can add PyFrame_GetLineNumber() to pythoncapi-compat if you want. Maybe using pythoncapi_compat.h can be done later.

@vstinner
Copy link
Contributor Author

If you want, you can wait until the downstream patch is merged into Fedora: https://src.fedoraproject.org/rpms/uwsgi/pull-request/11

Fedora is being updated to Python 3.11.

@vstinner
Copy link
Contributor Author

vstinner commented Jul 1, 2022

If you want, you can wait until the downstream patch is merged into Fedora: https://src.fedoraproject.org/rpms/uwsgi/pull-request/11

It got merged: https://src.fedoraproject.org/rpms/uwsgi/c/703b4ef92df1f0058bc07543fde9754de2fecc95?branch=rawhide

@xrmx
Copy link
Collaborator

xrmx commented Jul 1, 2022

Thanks a lot for the patch and for the heads up!

@xrmx xrmx merged commit 492c9c5 into unbit:master Jul 30, 2022
@vstinner vstinner deleted the python311 branch August 1, 2022 15:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

2 participants