Skip to content

gh-151218: Replace sys.flags in PyConfig_Set()#151402

Open
vstinner wants to merge 1 commit into
python:mainfrom
vstinner:replace_sys_flags
Open

gh-151218: Replace sys.flags in PyConfig_Set()#151402
vstinner wants to merge 1 commit into
python:mainfrom
vstinner:replace_sys_flags

Conversation

@vstinner

@vstinner vstinner commented Jun 12, 2026

Copy link
Copy Markdown
Member

PyConfig_Set() and sys.set_int_max_str_digits() now replace sys.flags, instead of modifying sys.flags in-place.

Modifying sys.flags in-place can lead to data races when multiple threads are reading or writing sys.flags in parallel.

Use _Py_atomic functions to get and set max_str_digits members.

PyConfig_Set() and sys.set_int_max_str_digits() now replace
sys.flags, instead of modifying sys.flags in-place.

Modifying sys.flags in-place can lead to data races when multiple
threads are reading or writing sys.flags in parallel.

Use _Py_atomic functions to get and set max_str_digits members.
@vstinner

Copy link
Copy Markdown
Member Author

I built Python with ./configure --with-pydebug --disable-gil --with-thread-sanitizer CC=clang LD=clang and I ran the reproducer: TSan doesn't report data races anymore.

If we agree that this change is the right approach, I will add a non-regression test.

@skirpichev skirpichev self-requested a review June 12, 2026 13:44

@skirpichev skirpichev left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think it's a correct approach.

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.

2 participants