Skip to content

Conversation

Viicos
Copy link
Member

@Viicos Viicos commented Mar 3, 2025

Change Summary

Fixes #10483.

Related issue number

Checklist

  • The pull request title is a good summary of the changes - it will be used in the changelog
  • Unit tests for the changes exist
  • Tests pass on CI
  • Documentation reflects the changes where applicable
  • My PR is ready to review, please add a comment including the phrase "please review" to assign reviewers

Viicos added 3 commits March 3, 2025 17:31
Similar logic to the recursion state
Nothing we can really do on these ones, the `generate_schema_calls`
fixture monkeypatches code and this will happen across threads.
@github-actions github-actions bot added the relnotes-fix Used for bugfixes. label Mar 3, 2025
Copy link

cloudflare-workers-and-pages bot commented Mar 3, 2025

Deploying pydantic-docs with  Cloudflare Pages  Cloudflare Pages

Latest commit: 03d03fd
Status: ✅  Deploy successful!
Preview URL: https://fdfb6bc1.pydantic-docs.pages.dev
Branch Preview URL: https://freethreaded.pydantic-docs.pages.dev

View logs

Copy link

codspeed-hq bot commented Mar 3, 2025

CodSpeed Performance Report

Merging #11516 will not alter performance

Comparing freethreaded (03d03fd) with main (50a7269)

Summary

✅ 46 untouched benchmarks

@@ -2149,6 +2150,7 @@ class Yard(BaseModel):
assert str(yard_dict['pet']['type']) == 'dog'


@pytest.mark.thread_unsafe(reason='Passes on multithreaded. This needs to be investigated further.')
Copy link
Member Author

@Viicos Viicos Mar 3, 2025

Choose a reason for hiding this comment

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

While all the other tests marked as thread unsafe made sense, I have no idea why this one passes. Core schemas are identical, and verified it isn't a late lambda binding issue. Might be something in core?

Copy link
Contributor

github-actions bot commented Mar 4, 2025

Coverage report

Click to see where and how coverage changed

FileStatementsMissingCoverageCoverage
(new stmts)
Lines missing
  pydantic/_internal
  _generics.py
Project Total  

This report was generated by python-coverage-comment-action

@Viicos Viicos changed the title Add support for freethreading Add initial support for freethreading Mar 4, 2025
@Viicos Viicos changed the title Add initial support for freethreading Add experimental support for freethreading Mar 5, 2025
@Viicos Viicos added relnotes-feature and removed relnotes-fix Used for bugfixes. labels Mar 5, 2025
Copy link
Contributor

@davidhewitt davidhewitt left a comment

Choose a reason for hiding this comment

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

Overall LGTM with one question!

@@ -94,7 +94,7 @@ def __delitem__(self, key: KT) -> None:
# and discover later on that we need to re-add all this infrastructure...
# _GENERIC_TYPES_CACHE = DeepChainMap(GenericTypesCache(), LimitedDict())

_GENERIC_TYPES_CACHE = GenericTypesCache()
_GENERIC_TYPES_CACHE: ContextVar[GenericTypesCache | None] = ContextVar('_GENERIC_TYPES_CACHE', default=None)
Copy link
Contributor

Choose a reason for hiding this comment

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

The idea here is to make a separate cache for each thread?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes exactly, identical to the recursion cache:

_generic_recursion_cache: ContextVar[set[str] | None] = ContextVar('_generic_recursion_cache', default=None)

@sydney-runkle
Copy link
Contributor

Makes sense to get this into the 2nd beta next week 👍

@Viicos Viicos changed the title Add experimental support for freethreading Add experimental support for free threading Mar 11, 2025
@Viicos Viicos merged commit 10af6a8 into main Mar 11, 2025
62 checks passed
@Viicos Viicos deleted the freethreaded branch March 11, 2025 15:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Python 3.13 freethreading support
3 participants