Skip to content

gh-116738: Test re module for free threading - #141923

Merged
colesbury merged 2 commits into
python:mainfrom
yoney:ft_sre
Nov 26, 2025
Merged

gh-116738: Test re module for free threading#141923
colesbury merged 2 commits into
python:mainfrom
yoney:ft_sre

Conversation

@yoney

@yoney yoney commented Nov 24, 2025

Copy link
Copy Markdown
Contributor
  • Added atomic operations to scanner_begin() and scanner_end() to prevent race conditions on the executing flag in free-threaded builds.
  • Added tests for concurrent usage of the re module.

Without the atomic operations, test_scanner_concurrent_access() triggers assert(self->executing) failures, or a thread sanitizer run emits errors.

cc: @mpage @colesbury

@yoney
yoney marked this pull request as ready for review November 24, 2025 22:23

@colesbury colesbury left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'd be inclined to include a NEWS entry. It can be something like:

Make the :func:`re.finditer` reentrancy detection thread-safe.
Comment thread Modules/_sre/sre.c Outdated
Comment thread Modules/_sre/sre.c Outdated
@yoney

yoney commented Nov 25, 2025

Copy link
Copy Markdown
Contributor Author

@colesbury Thank you for the review. I have updated the code to use atomics.
(I re-ran the tests under tsan build after the update.)

@colesbury colesbury left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks!

@colesbury
colesbury merged commit bc9e63d into python:main Nov 26, 2025
50 checks passed
@colesbury colesbury added the needs backport to 3.14 bugs and security fixes label Nov 26, 2025
@miss-islington-app

Copy link
Copy Markdown

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

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Nov 26, 2025
…ing (pythongh-141923)

Added atomic operations to `scanner_begin()` and `scanner_end()` to prevent
race conditions on the `executing` flag in free-threaded builds. Also added
tests for concurrent usage of the `re` module.

Without the atomic operations, `test_scanner_concurrent_access()` triggers
`assert(self->executing)` failures, or a thread sanitizer run emits errors.
(cherry picked from commit bc9e63d)

Co-authored-by: Alper <alperyoney@fb.com>
@bedevere-app

bedevere-app Bot commented Nov 26, 2025

Copy link
Copy Markdown

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

@bedevere-app bedevere-app Bot removed the needs backport to 3.14 bugs and security fixes label Nov 26, 2025
colesbury pushed a commit that referenced this pull request Nov 26, 2025
…ding (gh-141923) (gh-141990)

Added atomic operations to `scanner_begin()` and `scanner_end()` to prevent
race conditions on the `executing` flag in free-threaded builds. Also added
tests for concurrent usage of the `re` module.

Without the atomic operations, `test_scanner_concurrent_access()` triggers
`assert(self->executing)` failures, or a thread sanitizer run emits errors.
(cherry picked from commit bc9e63d)

Co-authored-by: Alper <alperyoney@fb.com>
StanFromIreland pushed a commit to StanFromIreland/cpython that referenced this pull request Dec 6, 2025
…ing (pythongh-141923)

Added atomic operations to `scanner_begin()` and `scanner_end()` to prevent
race conditions on the `executing` flag in free-threaded builds. Also added
tests for concurrent usage of the `re` module.

Without the atomic operations, `test_scanner_concurrent_access()` triggers
`assert(self->executing)` failures, or a thread sanitizer run emits errors.
@yoney
yoney deleted the ft_sre branch January 27, 2026 17:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants