GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — gh-159458: Fix free-threading data race in datetime strftime century normalization by AnnaAr321 · Pull Request #159520 · python/cpython

Conversation

@AnnaAr321

@AnnaAr321 AnnaAr321 commented Oct 16, 2026 •
edited by bedevere-app Bot
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

In Modules/_datetimemodule.c, normalize_century() lazily initializes a function-local static int cache = -1; on the first strftime() call using %Y, %G, %F, or %C. Under free-threaded builds (Py_GIL_DISABLED), concurrent initial calls to strftime() race on reading and writing cache, triggering ThreadSanitizer data race warnings.
Use FT_ATOMIC_LOAD_INT_RELAXED and FT_ATOMIC_STORE_INT_RELAXED to atomically load and store cache in free-threaded builds with zero overhead in default GIL-enabled builds.

  • Issue: Free-threading: data race on static cache in _datetime.normalize_century() #159458

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@AnnaAr321
Fix free-threading data race in datetime strftime century normalization
bb256a0
@AnnaAr321
AnnaAr321 requested review from StanFromIreland and pganssle as code owners October 16, 2026 10:23
@bedevere-app bedevere-app Bot mentioned this pull request Oct 16, 2026
Free-threading: data race on static cache in _datetime.normalize_century() #159458
Closed
@bedevere-app bedevere-app Bot added the awaiting review label Oct 16, 2026
@blurb-it
📜🤖 Added by blurb_it.
5b57447
@encukou

encukou commented Oct 16, 2026

Copy link
Copy Markdown
Member

Thank you.
AFAIK, this doesn't affect users in practice, so the NEWS blurb isn't really necessary. But since you already wrote it, we can keep it.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@encukou
encukou merged commit ddc647a into python:main Oct 16, 2026
56 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-app bedevere-app Bot removed the awaiting review label Oct 16, 2026
@encukou encukou added awaiting review needs backport to 3.14 bugs and security fixes needs backport to 3.15 bugs and security fixes labels Oct 16, 2026
@miss-islington-app

miss-islington-app Bot commented Oct 16, 2026

Copy link
Copy Markdown

Thanks @AnnaAr321 for the PR, and @encukou for merging it 🌮🎉.. I'm working now to backport this PR to: 3.15.
🐍🍒⛏🤖

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@miss-islington-app

miss-islington-app Bot commented Oct 16, 2026

Copy link
Copy Markdown

Thanks @AnnaAr321 for the PR, and @encukou for merging it 🌮🎉.. I'm working now to backport this PR to: 3.14.
🐍🍒⛏🤖

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-app

bedevere-app Bot commented Oct 16, 2026

Copy link
Copy Markdown

GH-159536 is a backport of this pull request to the 3.15 branch.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-app bedevere-app Bot removed the needs backport to 3.15 bugs and security fixes label Oct 16, 2026
@bedevere-app

bedevere-app Bot commented Oct 16, 2026

Copy link
Copy Markdown

GH-159537 is a backport of this pull request to the 3.14 branch.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-app bedevere-app Bot removed the needs backport to 3.14 bugs and security fixes label Oct 16, 2026
StanFromIreland
StanFromIreland reviewed Oct 16, 2026
View reviewed changes

@StanFromIreland StanFromIreland left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

This was merged before I could review it, so a couple of notes for future PRs.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread Lib/test/test_free_threading/test_datetime.py

@threading_helper.requires_working_threading()
class TestDatetime(unittest.TestCase):
def test_concurrent_strftime_normalize_century(self):

@StanFromIreland StanFromIreland Oct 16, 2026

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

I think this test does not work in our current testing configuration, as it relies on the cache being empty, correct? In the CI job the whole suite runs in parallel threads, so by the time this test runs the cache is almost certainly already initialised...

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

encukou reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
Comment thread Misc/NEWS.d/next/Library/2026-10-16-10-25-22.gh-issue-159458.q02EnY.rst
@@ -0,0 +1 @@
Fix a ThreadSanitizer data race on the static cache in ``normalize_century()`` of the datetime module under the free-threaded build.

@StanFromIreland StanFromIreland Oct 16, 2026

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Suggested change
Fix a ThreadSanitizer data race on the static cache in ``normalize_century()`` of the datetime module under the free-threaded build.
Fix a data race in :meth:`datetime.date.strftime` and :meth:`datetime.datetime.strftime` on the free-threaded build.

Please only include user-facing details in blurbs.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
corona10 pushed a commit that referenced this pull request Oct 20, 2026
@miss-islington @AnnaAr321
[3.15] gh-159458: Fix free-threading data race in datetime strftime c…
d89f40b
…entury normalization (GH-159520) (gh-159536)

gh-159458: Fix free-threading data race in datetime strftime century normalization (GH-159520)
(cherry picked from commit ddc647a)

Co-authored-by: Anna <[email protected]>
corona10 pushed a commit that referenced this pull request Oct 20, 2026
@miss-islington @AnnaAr321
[3.14] gh-159458: Fix free-threading data race in datetime strftime c…
9d6f05e
…entury normalization (GH-159520) (gh-159537)

gh-159458: Fix free-threading data race in datetime strftime century normalization (GH-159520)
(cherry picked from commit ddc647a)

Co-authored-by: Anna <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@StanFromIreland StanFromIreland StanFromIreland left review comments
@pganssle pganssle Awaiting requested review from pganssle pganssle is a code owner

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

awaiting review

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

3 participants

@AnnaAr321 @encukou @StanFromIreland
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.