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

Build failure with CPython main (3.11). #2365

Closed
ericsnowcurrently opened this issue Nov 10, 2021 · 12 comments
Closed

Build failure with CPython main (3.11). #2365

ericsnowcurrently opened this issue Nov 10, 2021 · 12 comments

Comments

@ericsnowcurrently
Copy link

pip-installing uWSGI with the main branch of the CPython repo ends in failures due to deprecations in the C-API.

git clone https://github.com/python/cpython
pushd cpython
./configure
make
popd
cpython/python -m venv my-venv
my-venv/bin/python3 -m pip install uWSGI
I end up with output like this:
  Building wheel for uWSGI (setup.py) ... error
  ERROR: Command errored out with exit status 1:
   command: venv/bin/python -u -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-j89w7vcn/uwsgi_66b78e80c52e4eb2bf13c0c74153db1b/setup.py'"'"'; __file__='"'"'/tmp/pip-install-j89w7vcn/uwsgi_66b78e80c52e4eb2bf13c0c74153db1b/setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'
\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' bdist_wheel -d /tmp/pip-wheel-_3lxoo27
       cwd: /tmp/pip-install-j89w7vcn/uwsgi_66b78e80c52e4eb2bf13c0c74153db1b/
  Complete output (308 lines):
  cpython/Lib/distutils/dist.py:274: UserWarning: Unknown distribution option: 'descriptions'
    warnings.warn(msg)
  running bdist_wheel
  running build
  running build_py
  creating build
  creating build/lib
  copying uwsgidecorators.py -> build/lib
  my-venv/lib/python3.11/site-packages/setuptools/command/install.py:34: SetuptoolsDeprecationWarning: setup.py install is deprecated. Use build and pip and other standards-based tools.
    warnings.warn(
  installing to build/bdist.linux-x86_64/wheel
  running install
  using profile: buildconf/default.ini
  detected include path: ['/usr/lib/gcc/x86_64-linux-gnu/7/include', '/usr/local/include', '/usr/lib/gcc/x86_64-linux-gnu/7/include-fixed', '/usr/include/x86_64-linux-gnu', '/usr/include']
  Patching "bin_name" to properly install_scripts dir
  detected CPU cores: 8
  configured CFLAGS: -O2 -I. -Wall -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -Wextra -Wno-unused-parameter -Wno-missing-field-initializers -DUWSGI_HAS_IFADDRS -DUWSGI_ZLIB -DUWSGI_LOCK_USE_MUTEX -DUWSGI_EVENT_USE_EPOLL -DUWSGI_EVENT_TIMER_USE_TIMERFD -DUWSGI_EVENT_FILEMONITOR_USE_INOTIFY  -DUWSGI_PCRE -DUWSGI_ROUTING -DUWSGI_VERSION="\"2.0.19.1\"" -DUWSGI_VERSION_BASE="2" -DUWSGI_VERSION_MAJOR="0" -DUWSGI_VERSION_MINOR="19" -DUWSGI_VERSION_REVISION="1" -DUWSGI_VERSION_CUSTOM="\"\"" -DUWSGI_YAML -DUWSGI_SSL -I/usr/include/libxml2 -DUWSGI_X
ML -DUWSGI_XML_LIBXML2 -DUWSGI_PLUGIN_DIR="\".\"" -DUWSGI_DECLARE_EMBEDDED_PLUGINS="UDEP(python);UDEP(gevent);UDEP(ping);UDEP(cache);UDEP(nagios);UDEP(rrdtool);UDEP(carbon);UDEP(rpc);UDEP(corerouter);UDEP(fastrouter);UDEP(http);UDEP(ugreen);UDEP(signal);UDEP(syslog);UDEP(rsyslog);UDEP(logsocket);UDEP(router_uwsgi);UDEP(router_redirect);UDEP(router_basicauth);UDEP(zergpool);UDEP(redislog);UDEP(mongodblog);UDEP(router_rewrite);UDEP(router_http);UDEP(logfile);UDEP(router_cache);UDEP(rawrouter);UDEP(router_static);UDEP(sslrouter);UDEP(spooler)
;UDEP(cheaper_busyness);UDEP(symcall);UDEP(transformation_tofile);UDEP(transformation_gzip);UDEP(transformation_chunked);UDEP(transformation_offload);UDEP(router_memcached);UDEP(router_redis);UDEP(router_hash);UDEP(router_expires);UDEP(router_metrics);UDEP(transformation_template);UDEP(stats_pusher_socket);" -DUWSGI_LOAD_EMBEDDED_PLUGINS="ULEP(python);ULEP(gevent);ULEP(ping);ULEP(cache);ULEP(nagios);ULEP(rrdtool);ULEP(carbon);ULEP(rpc);ULEP(corerouter);ULEP(fastrouter);ULEP(http);ULEP(ugreen);ULEP(signal);ULEP(syslog);ULEP(rsyslog);ULEP(lo
gsocket);ULEP(router_uwsgi);ULEP(router_redirect);ULEP(router_basicauth);ULEP(zergpool);ULEP(redislog);ULEP(mongodblog);ULEP(router_rewrite);ULEP(router_http);ULEP(logfile);ULEP(router_cache);ULEP(rawrouter);ULEP(router_static);ULEP(sslrouter);ULEP(spooler);ULEP(cheaper_busyness);ULEP(symcall);ULEP(transformation_tofile);ULEP(transformation_gzip);ULEP(transformation_chunked);ULEP(transformation_offload);ULEP(router_memcached);ULEP(router_redis);ULEP(router_hash);ULEP(router_expires);ULEP(router_metrics);ULEP(transformation_template);ULEP(s
tats_pusher_socket);"
  *** uWSGI compiling server core ***
  [thread 2][gcc -pthread] core/utils.o
  [thread 0][gcc -pthread] core/protocol.o
  [thread 4][gcc -pthread] core/socket.o
  [thread 3][gcc -pthread] core/logging.o
  [thread 5][gcc -pthread] core/master.o
  [thread 1][gcc -pthread] core/master_utils.o
  [thread 6][gcc -pthread] core/emperor.o
  [thread 7][gcc -pthread] core/notify.o
  [thread 7][gcc -pthread] core/mule.o
  [thread 0][gcc -pthread] core/subscription.o
  [thread 1][gcc -pthread] core/stats.o
  [thread 4][gcc -pthread] core/sendfile.o
  [thread 7][gcc -pthread] core/async.o
  [thread 5][gcc -pthread] core/master_checks.o
  [thread 3][gcc -pthread] core/fifo.o
  [thread 4][gcc -pthread] core/offload.o
  [thread 6][gcc -pthread] core/io.o
  [thread 3][gcc -pthread] core/static.o
  [thread 0][gcc -pthread] core/websockets.o
  [thread 7][gcc -pthread] core/spooler.o
  [thread 5][gcc -pthread] core/snmp.o
  [thread 1][gcc -pthread] core/exceptions.o
  [thread 4][gcc -pthread] core/config.o
  [thread 7][gcc -pthread] core/setup_utils.o
  [thread 3][gcc -pthread] core/clock.o
  [thread 0][gcc -pthread] core/init.o
  [thread 1][gcc -pthread] core/buffer.o
  [thread 5][gcc -pthread] core/reader.o
  [thread 2][gcc -pthread] core/writer.o
  [thread 6][gcc -pthread] core/alarm.o
  [thread 7][gcc -pthread] core/cron.o
  [thread 3][gcc -pthread] core/hooks.o
  [thread 4][gcc -pthread] core/plugins.o
  [thread 0][gcc -pthread] core/lock.o
  [thread 1][gcc -pthread] core/cache.o
  [thread 5][gcc -pthread] core/daemons.o
  [thread 7][gcc -pthread] core/errors.o
  [thread 6][gcc -pthread] core/hash.o
  [thread 4][gcc -pthread] core/master_events.o
  [thread 3][gcc -pthread] core/chunked.o
  [thread 2][gcc -pthread] core/queue.o
  [thread 0][gcc -pthread] core/event.o
  [thread 5][gcc -pthread] core/signal.o
  [thread 4][gcc -pthread] core/strings.o
  [thread 3][gcc -pthread] core/progress.o
  [thread 7][gcc -pthread] core/timebomb.o
  [thread 6][gcc -pthread] core/ini.o
  [thread 2][gcc -pthread] core/fsmon.o
  [thread 7][gcc -pthread] core/mount.o
  [thread 6][gcc -pthread] core/metrics.o
  [thread 0][gcc -pthread] core/plugins_builder.o
  [thread 3][gcc -pthread] core/sharedarea.o
  [thread 5][gcc -pthread] core/rpc.o
  [thread 4][gcc -pthread] core/gateway.o
  [thread 1][gcc -pthread] core/loop.o
  [thread 7][gcc -pthread] core/cookie.o
  [thread 2][gcc -pthread] core/querystring.o
  [thread 0][gcc -pthread] core/rb_timers.o
  [thread 5][gcc -pthread] core/transformations.o
  [thread 7][gcc -pthread] core/uwsgi.o
  [thread 4][gcc -pthread] proto/base.o
  [thread 2][gcc -pthread] proto/uwsgi.o
  [thread 3][gcc -pthread] proto/http.o
  [thread 1][gcc -pthread] proto/fastcgi.o
  [thread 5][gcc -pthread] proto/scgi.o
  [thread 6][gcc -pthread] proto/puwsgi.o
  [thread 0][gcc -pthread] lib/linux_ns.o
  [thread 2][gcc -pthread] core/zlib.o
  [thread 1][gcc -pthread] core/regexp.o
  [thread 5][gcc -pthread] core/routing.o
  [thread 4][gcc -pthread] core/yaml.o
  [thread 6][gcc -pthread] core/ssl.o
  [thread 0][gcc -pthread] core/legion.o
  [thread 2][gcc -pthread] core/xmlconf.o
  [thread 1][gcc -pthread] core/dot_h.o
  [thread 1][gcc -pthread] core/config_py.o
  *** uWSGI compiling embedded plugins ***
  [thread 4][gcc -pthread] plugins/python/python_plugin.o
  [thread 1][gcc -pthread] plugins/python/pyutils.o
  [thread 3][gcc -pthread] plugins/python/pyloader.o
  [thread 6][gcc -pthread] plugins/python/wsgi_handlers.o
  [thread 2][gcc -pthread] plugins/python/wsgi_headers.o
  plugins/python/pyloader.c: In function ‘uwsgi_pecan_loader’:
  plugins/python/pyloader.c:663:2: warning: ‘PyEval_CallObjectWithKeywords’ is deprecated [-Wdeprecated-declarations]
    pecan_app = PyEval_CallObject(pecan_deploy, pecan_arg);
    ^~~~~~~~~
  In file included from cpython/Include/Python.h:93:0,
                   from plugins/python/uwsgi_python.h:2,
                   from plugins/python/pyloader.c:1:
  cpython/Include/ceval.h:27:43: note: declared here
   Py_DEPRECATED(3.9) PyAPI_FUNC(PyObject *) PyEval_CallObjectWithKeywords(
                                             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
...
  plugins/python/pyloader.c: In function ‘uwsgi_eval_loader’:
  plugins/python/pyloader.c:745:19: warning: implicit declaration of function ‘PyParser_SimpleParseString’; did you mean ‘PyRun_SimpleString’? [-Wimplicit-function-declaration]
    wsgi_eval_node = PyParser_SimpleParseString(code, Py_file_input);
                     ^~~~~~~~~~~~~~~~~~~~~~~~~~
                     PyRun_SimpleString
  plugins/python/pyloader.c:745:17: warning: assignment makes pointer from integer without a cast [-Wint-conversion]
    wsgi_eval_node = PyParser_SimpleParseString(code, Py_file_input);
                   ^
  plugins/python/pyloader.c:752:36: warning: implicit declaration of function ‘PyNode_Compile’; did you mean ‘Py_GetCompiler’? [-Wimplicit-function-declaration]
    wsgi_compiled_node = (PyObject *) PyNode_Compile(wsgi_eval_node, "uwsgi_eval_config");
                                      ^~~~~~~~~~~~~~
                                      Py_GetCompiler
  plugins/python/pyloader.c:752:23: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
    wsgi_compiled_node = (PyObject *) PyNode_Compile(wsgi_eval_node, "uwsgi_eval_config");
                         ^
...
  plugins/python/wsgi_subhandler.c: In function ‘uwsgi_response_subhandler_wsgi’:
  plugins/python/wsgi_subhandler.c:366:25: warning: ‘PyEval_CallObjectWithKeywords’ is deprecated [-Wdeprecated-declarations]
                           PyObject *close_method_output = PyEval_CallObject(close_method, close_method_args);
                           ^~~~~~~~
  In file included from /home/esnow/projects/work/cpython-perf/cpython/Include/Python.h:93:0,
                   from plugins/python/uwsgi_python.h:2,
                   from plugins/python/wsgi_subhandler.c:1:
  /home/esnow/projects/work/cpython-perf/cpython/Include/ceval.h:27:43: note: declared here
   Py_DEPRECATED(3.9) PyAPI_FUNC(PyObject *) PyEval_CallObjectWithKeywords(
                                             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  ----------------------------------------
  ERROR: Failed building wheel for uWSGI
  Running setup.py clean for uWSGI
Failed to build uWSGI
@xrmx
Copy link
Collaborator

xrmx commented Nov 10, 2021

Thanks for reporting. Looks like there's documentation on what to use instead of PyParser_SimpleParseString and PyEval_CallObjectWithKeywords but can't see anything on python 3.9 release notes for a PyNode_Compile substitution. Any hint?

@ericsnowcurrently
Copy link
Author

ericsnowcurrently commented Nov 10, 2021

Thanks for taking a look so quickly!

Just to be clear, the text I included above is only a sample of the output I saw.

Here's the full list or errors and warnings, grouped:
Errors:

plugins/python/python_plugin.c:1535:50: error: ‘PyThreadState {aka struct _ts}’ has no member named ‘frame’; did you mean ‘cframe’?
plugins/python/python_plugin.c:1539:35: error: ‘PyThreadState {aka struct _ts}’ has no member named ‘frame’; did you mean ‘cframe’?
plugins/python/python_plugin.c:1768:11: error: ‘PyThreadState {aka struct _ts}’ has no member named ‘frame’; did you mean ‘cframe’?
plugins/python/python_plugin.c:1772:11: error: ‘PyThreadState {aka struct _ts}’ has no member named ‘frame’; did you mean ‘cframe’?

Warnings (old C-API symbols removed):

plugins/python/pyloader.c:745:19: warning: implicit declaration of function ‘PyParser_SimpleParseString’; did you mean ‘PyRun_SimpleString’? [-Wimplicit-function-declaration]
plugins/python/pyloader.c:752:36: warning: implicit declaration of function ‘PyNode_Compile’; did you mean ‘Py_GetCompiler’? [-Wimplicit-function-declaration]
plugins/python/python_plugin.c:470:18: warning: implicit declaration of function ‘PyParser_SimpleParseFile’; did you mean ‘PyRun_SimpleFile’? [-Wimplicit-function-declaration]
plugins/python/python_plugin.c:487:19: warning: implicit declaration of function ‘PyParser_SimpleParseString’; did you mean ‘PyRun_SimpleString’? [-Wimplicit-function-declaration]
plugins/python/python_plugin.c:496:34: warning: implicit declaration of function ‘PyNode_Compile’; did you mean ‘Py_GetCompiler’? [-Wimplicit-function-declaration]

Warnings (C-API Deprecation):

plugins/python/python_plugin.c:235:3: warning: ‘Py_SetPythonHome’ is deprecated [-Wdeprecated-declarations]
plugins/python/python_plugin.c:259:2: warning: ‘Py_SetProgramName’ is deprecated [-Wdeprecated-declarations]
plugins/python/python_plugin.c:1292:2: warning: ‘PyEval_InitThreads’ is deprecated [-Wdeprecated-declarations]

Warnings (C-API Deprecation -- use of PyEval_CallObject(), which evaluates to PyEval_CallObjectWithKeywords()):

plugins/python/pyloader.c:663:2: warning: ‘PyEval_CallObjectWithKeywords’ is deprecated [-Wdeprecated-declarations]
plugins/python/pyloader.c:727:2: warning: ‘PyEval_CallObjectWithKeywords’ is deprecated [-Wdeprecated-declarations]
plugins/python/pyutils.c:78:2: warning: ‘PyEval_CallObjectWithKeywords’ is deprecated [-Wdeprecated-declarations]
plugins/python/pyutils.c:279:2: warning: ‘PyEval_CallObjectWithKeywords’ is deprecated [-Wdeprecated-declarations]
plugins/python/python_plugin.c:319:33: warning: ‘PyEval_CallObjectWithKeywords’ is deprecated [-Wdeprecated-declarations]
plugins/python/python_plugin.c:1336:33: warning: ‘PyEval_CallObjectWithKeywords’ is deprecated [-Wdeprecated-declarations]
plugins/python/python_plugin.c:1424:33: warning: ‘PyEval_CallObjectWithKeywords’ is deprecated [-Wdeprecated-declarations]
plugins/python/python_plugin.c:1854:4: warning: ‘PyEval_CallObjectWithKeywords’ is deprecated [-Wdeprecated-declarations]
plugins/python/python_plugin.c:1944:17: warning: ‘PyEval_CallObjectWithKeywords’ is deprecated [-Wdeprecated-declarations]
plugins/python/wsgi_subhandler.c:106:10: warning: ‘PyEval_CallObjectWithKeywords’ is deprecated [-Wdeprecated-declarations]
plugins/python/wsgi_subhandler.c:366:25: warning: ‘PyEval_CallObjectWithKeywords’ is deprecated [-Wdeprecated-declarations]
plugins/python/raw.c:67:2: warning: ‘PyEval_CallObjectWithKeywords’ is deprecated [-Wdeprecated-declarations]

Warnings (other):

plugins/python/pyloader.c:49:21: warning: ‘__builtin___snprintf_chk’ output truncated before the last format character [-Wformat-truncation=]
                 if (snprintf(venv_version, 15, "/lib/python%d.%d", PY_MAJOR_VERSION, PY_MINOR_VERSION) == -1) {

That boils down to:

  • relying on PyThreadState internals (tstate->frame)
  • using old C-API functions that were removed in 3.10
    • PyNode_Compile()
    • PyParser_SimpleParseString()
    • PyParser_SimpleParseFile()
    • PyParser_SimpleParseString()
    • ()
  • using deprecated C-API functions
    • Py_SetPythonHome()
    • Py_SetProgramName()
    • PyEval_InitThreads()
    • PyEval_CallObject() (which evaluates to the deprecated PyEval_CallObjectWithKeywords())
  • assuming the Python version is always 3 characters, e.g. 3.9 (presumably this warning started happening with 3.10)

(Note that you will need to fix all these, except PyThreadState for 3.10 as well.)

For PyThreadState, take a look at PyThreadState_GetFrame().

For the removed functions, including PyNode_Compile(), see https://docs.python.org/3.11/whatsnew/3.10.html#changes-in-the-c-api.

For PyEval_InitThreads(), you can stop using it now. See https://docs.python.org/3.11/whatsnew/3.9.html#deprecated.

For PyEval_CallObject(), instead use PyObject_Call() or one of its variants. See https://docs.python.org/3/whatsnew/3.9.html?highlight=pyeval_callobject#changes-in-the-c-api.

For the other deprecated functions, see https://docs.python.org/3.11/whatsnew/3.11.html#id3

I'll leave the snprintf() warning to you. 🙂

@xrmx
Copy link
Collaborator

xrmx commented Nov 11, 2021

Thanks! much appreciated.

@xrmx
Copy link
Collaborator

xrmx commented Nov 14, 2021

Took a stab at fixing these, first of all it looks like you tested this with a version < 2.0.20 where the 3.10 issues are already fixed. On master switching Py_SetPythonHome() and Py_SetProgramName() to PyConfig was easy, need to dig quite a bit to sort out what to do with PyThreadState internals though.

@ericsnowcurrently
Copy link
Author

If the only error is about using PyThreadState.frame then try PyThreadState_GetFrame().

@ericsnowcurrently
Copy link
Author

Anything I can do to help with this?

@xrmx
Copy link
Collaborator

xrmx commented Dec 8, 2021

Anything I can do to help with this?

If you can take a look plugins/python/python_plugin.c and propose a patch that would be much appreciated :)

@Lalufu
Copy link
Contributor

Lalufu commented Jun 22, 2022

I'm currently running into this as Fedora is preparing to move to 3.11 for the upcoming release, and trying to understand what the uwsgi/python code is trying to accomplish here.
Getting the current frame with PyThreadState_GetFrame() might be doable, but other parts of the code also restore the frame pointer into the python threadstate, and there's no function for that that I can find.
The code also saves/restores recursion metadata from the threadstate which needs to change with 3.11.
I'm wondering if just saving/restoring the entire threadstate via PyEval_SaveThread and PyEval_RestoreThread would work instead?
Unfortunately I know little about python threads, and even less about what uwsgi does with them.

@JCavallo
Copy link

It looks like building on master (879c413) is ok on CPython 3.11.0rc2.

I think this issue should be closed as a duplicate of #2453

@xrmx
Copy link
Collaborator

xrmx commented Oct 24, 2022

Should be fixed in 2.0.21. Still we'll have issues with stuff deprecated that will be removed in 3.12.

@xrmx xrmx closed this as completed Oct 24, 2022
@stevepepple
Copy link

On Fedora this did the trick for me:

sudo dnf install python3.11-devel.x86_64

@Lalufu
Copy link
Contributor

Lalufu commented Feb 17, 2023 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants