Skip to content

Build failure on Python3.11 #36

Closed

Description

@AlexanderWells-diamond

It seems cothread cannot be built on Python 3.11. It looks like the API for PyThreadState has changed.

The errors reported by a CI build in pythonSoftIOC are:

 building 'cothread._coroutine' extension
        creating build/temp.linux-x86_64-cpython-311
        creating build/temp.linux-x86_64-cpython-311/context
        gcc -pthread -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -fPIC -I/tmp/tmp.3osZKRDAwo/venv/include -I/opt/_internal/cpython-3.11.1/include/python3.11 -c context/_coroutine.c -o build/temp.linux-x86_64-cpython-311/context/_coroutine.o -Wall -Wextra -Wno-unused-parameter -Wno-missing-field-initializers -Wundef -Wcast-align -Wwrite-strings -Wmissing-prototypes -Wmissing-declarations -Wstrict-prototypes
        context/_coroutine.c: In function ‘coroutine_wrapper’:
        context/_coroutine.c:83:19: error: ‘PyThreadState’ {aka ‘struct _ts’} has no member named ‘frame’; did you mean ‘cframe’?
           83 |     thread_state->frame = NULL;
              |                   ^~~~~
              |                   cframe
        context/_coroutine.c:84:19: error: ‘PyThreadState’ {aka ‘struct _ts’} has no member named ‘recursion_depth’; did you mean ‘recursion_limit’?
           84 |     thread_state->recursion_depth = 0;
              |                   ^~~~~~~~~~~~~~~
              |                   recursion_limit
        In file included from /opt/_internal/cpython-3.11.1/include/python3.11/Python.h:38,
                         from context/_coroutine.c:33:
        context/_coroutine.c:110:30: error: ‘PyThreadState’ {aka ‘struct _ts’} has no member named ‘frame’; did you mean ‘cframe’?
          110 |     Py_XDECREF(thread_state->frame);
              |                              ^~~~~
        /opt/_internal/cpython-3.11.1/include/python3.11/pyport.h:24:38: note: in definition of macro ‘_Py_CAST’
           24 | #define _Py_CAST(type, expr) ((type)(expr))
              |                                      ^~~~
        /opt/_internal/cpython-3.11.1/include/python3.11/object.h:606:37: note: in expansion of macro ‘_PyObject_CAST’
          606 | #  define Py_XDECREF(op) Py_XDECREF(_PyObject_CAST(op))
              |                                     ^~~~~~~~~~~~~~
        context/_coroutine.c:110:5: note: in expansion of macro ‘Py_XDECREF’
          110 |     Py_XDECREF(thread_state->frame);
              |     ^~~~~~~~~~
        context/_coroutine.c:112:39: error: ‘_PyErr_StackItem’ {aka ‘struct _err_stackitem’} has no member named ‘exc_type’
          112 |     Py_XDECREF(thread_state->exc_state.exc_type);
              |                                       ^
        /opt/_internal/cpython-3.11.1/include/python3.11/pyport.h:24:38: note: in definition of macro ‘_Py_CAST’
           24 | #define _Py_CAST(type, expr) ((type)(expr))
              |                                      ^~~~
        /opt/_internal/cpython-3.11.1/include/python3.11/object.h:606:37: note: in expansion of macro ‘_PyObject_CAST’
          606 | #  define Py_XDECREF(op) Py_XDECREF(_PyObject_CAST(op))
              |                                     ^~~~~~~~~~~~~~
        context/_coroutine.c:112:5: note: in expansion of macro ‘Py_XDECREF’
          112 |     Py_XDECREF(thread_state->exc_state.exc_type);
              |     ^~~~~~~~~~
        context/_coroutine.c:114:39: error: ‘_PyErr_StackItem’ {aka ‘struct _err_stackitem’} has no member named ‘exc_traceback’
          114 |     Py_XDECREF(thread_state->exc_state.exc_traceback);
              |                                       ^
        /opt/_internal/cpython-3.11.1/include/python3.11/pyport.h:24:38: note: in definition of macro ‘_Py_CAST’
           24 | #define _Py_CAST(type, expr) ((type)(expr))
              |                                      ^~~~
        /opt/_internal/cpython-3.11.1/include/python3.11/object.h:606:37: note: in expansion of macro ‘_PyObject_CAST’
          606 | #  define Py_XDECREF(op) Py_XDECREF(_PyObject_CAST(op))
              |                                     ^~~~~~~~~~~~~~
        context/_coroutine.c:114:5: note: in expansion of macro ‘Py_XDECREF’
          114 |     Py_XDECREF(thread_state->exc_state.exc_traceback);
              |     ^~~~~~~~~~
        context/_coroutine.c: In function ‘coroutine_switch’:
        context/_coroutine.c:156:53: error: ‘PyThreadState’ {aka ‘struct _ts’} has no member named ‘frame’; did you mean ‘cframe’?
          156 |         struct _frame *python_frame = thread_state->frame;
              |                                                     ^~~~~
              |                                                     cframe
        context/_coroutine.c:157:45: error: ‘PyThreadState’ {aka ‘struct _ts’} has no member named ‘recursion_depth’; did you mean ‘recursion_limit’?
          157 |         int recursion_depth = thread_state->recursion_depth;
              |                                             ^~~~~~~~~~~~~~~
              |                                             recursion_limit
        context/_coroutine.c:181:23: error: ‘PyThreadState’ {aka ‘struct _ts’} has no member named ‘frame’; did you mean ‘cframe’?
          181 |         thread_state->frame = python_frame;
              |                       ^~~~~
              |                       cframe
        context/_coroutine.c:182:23: error: ‘PyThreadState’ {aka ‘struct _ts’} has no member named ‘recursion_depth’; did you mean ‘recursion_limit’?
          182 |         thread_state->recursion_depth = recursion_depth;
              |                       ^~~~~~~~~~~~~~~
              |                       recursion_limit
        error: command '/opt/rh/devtoolset-10/root/usr/bin/gcc' failed with exit code 1
        [end of output]

Activity

  1. Araneidae commented on Mar 10, 2023

    @Araneidae
    Collaborator

    This is not looking good. There has been a massive restructuring of the stack frame handling code. I think this issue: python/cpython#84128 tracks a lot of the work and motivation involved. I'm particularly troubled by this motivating comment:

    python/cpython#84128 (comment)

    I would be nice to make the PyThreadState opaque in Python 3.12.

    I suspect I'm not in a position to track this kind of change anymore.

  2. Araneidae commented on Mar 14, 2023

    @Araneidae
    Collaborator

    Ok, it looks as if https://github.com/python-greenlet/greenlet have also had to track the same issue, perhaps python-greenlet/greenlet@fd0b68a needs to be examined for guidance.

    Other potentially relevant links:

  3. zhangt58 commented on May 26, 2023

    @zhangt58

    To prepare to build the package for Debian Bookworm, I also encountered the same build errors from pip install cothread. After reading this thread, it seems tricky. Alternatively, do you have any way to recommend replacing cothread usecases with aioca?

  4. Araneidae commented on May 30, 2023

    @Araneidae
    Collaborator

    There is a plan for @AlexanderWells-diamond to take a look at porting the greenlet fixes to cothread some time later this summer. However, you should be able to use aioca for many of your applications, in particular softioc works with either framework.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions