Skip to content

Plan to support free-threaded Python #1555

New issue

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

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

Already on GitHub? # to your account

Closed
rostan-t opened this issue Nov 22, 2024 · 6 comments · Fixed by #1628
Closed

Plan to support free-threaded Python #1555

rostan-t opened this issue Nov 22, 2024 · 6 comments · Fixed by #1628

Comments

@rostan-t
Copy link

rostan-t commented Nov 22, 2024

In free-threaded build, importing pydantic_core currently results in a segmentation fault. PyO3 v0.23 introduces support for free-threaded Python and addresses this issue. Is there any short-term plan to migrate to PyO3 0.23?

Currently I see the following blockers:

  • Jiter support for free-threaded Python (support free-threaded Python jiter#165)
  • Making SerializationCallable Sync, which isn't because of CollectWarnings and SerRecursionState contain RefCells
  • Replacing IntoPy/ToPyObject by IntoPyObject
  • Replacing calls to deprecated APIs (*_bound methods, into_py/to_object)
@davidhewitt
Copy link
Contributor

Yes, I was testing PyO3 0.23 (when it was just a git branch) in #1450 and plan to proceed further with that upgrade this week.

There is potentially additional work required beyond your list to actually make free-threaded support ok, both here and in pydantic (where there are a bunch of caches which may or may not be thread-safe).

@davidhewitt
Copy link
Contributor

davidhewitt commented Dec 2, 2024

PyO3 has now been bumped but there's a build failure on aarch64 on main. I'm trying to identify the cause. Before we can call free-threaded Python supported we should probably add extensive testing here and downstream in the pydantic main Python repo. I think this is realistically a Pydantic 2.11 feature cc @pydantic/oss

@samuelcolvin
Copy link
Member

@sydney-runkle @Viicos this should go on the TODO list for Pydantic 2.11.

@davidhewitt
Copy link
Contributor

For what it's worth, the build failures are fixed so we could move forward here in core relatively quickly. I fear that upstream pydantic is likely to be harder due to caches.

@davidhewitt
Copy link
Contributor

We merged a test run in #1626, which is the first step. Build still fails, so fixing that will need to happen next.

@davidhewitt
Copy link
Contributor

After #1628 the free-threaded test suite is all happy except for assertions dependent on inline-snapshot (where free-threaded support is pending). As far as I am concerned, free-threading now works fine in pydantic-core.

The work will now be in pydantic main package, to add testing etc. Follow at pydantic/pydantic#10483

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

Successfully merging a pull request may close this issue.

3 participants