Skip to content

ENH: Free-Threading (No-GIL) Support for Python 3.13+ #130

Description

@HaoZeke

As I see it (from a first look), the primary issue from a design perspective is to have all the Python threads synchronously access only one running scs instance. It is unclear if scs itself has any locking or design decisions around concurrency.

For the bindings here, it should mean introducing an instance-level lock within the SCS struct.

The standard TODOs for adding free-threading support are in two phases, the first of which is a baseline consisting of the following tasks:

  • Run the test suite with pytest-run-parallel to find potential issues, and fix them.
  • Run the test suite under ThreadSanitizer. If possible, depends on how many dependencies there are and if they run under TSan.
  • Add cp313t-* to CI to build free-threading wheels.

The next phase is a bit more invasive, and it involves a single task:

For more details, please see the suggested plan of attack in the py-free-threading guide. The two phase approach is discussed in explosion/cymem#47 (comment) and gorakhargosh/watchdog#1105 (comment).

Note that this is the first time I've looked at this repo, so I might be
missing known issues or code that needs closer inspection. Any suggestions here
will be very useful.

Let me know if I ought to hold off for any reason.

Activity

  1. HaoZeke commented on Jun 1, 2025

    @HaoZeke
    ContributorAuthor

    Initial thoughts..

    uv venv --python 3.13t .ftci
    source .ftci/bin/activate
    uv pip install numpy scipy pytest-timeout pytest-durations pytest-run-parallel  
    uv pip install -v .
    uv run --no-project python -Xgil=0 -m pytest --parallel-threads=2 --iterations=2 -v -s --timeout=600 --durations=10 -m "not thread_unsafe"

    has one failure

    PARALLEL FAILED test/test_solve_random_cone_prob.py::test_solve_feasible[True-False] - AssertionError: 

    Which goes away without --iterations.

  2. bodono commented on Jun 13, 2025

    @bodono
    Owner

    Yes, it would be great to enable this, thanks for taking a look!

  3. added 3 commits that reference this issue on Apr 4, 2026
    c95a34a
    e49a22c
    e5a6321
  4. added a commit that references this issue on Apr 17, 2026
    151b415
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions