Skip to content

gh-145912: Add a free-threading section on testing with ThreadSanitizer - #161165

Open
johng wants to merge 3 commits into
python:mainfrom
johng:docs-ft-tsan
Open

johng wants to merge 3 commits into
python:mainfrom
johng:docs-ft-tsan

Conversation

@johng

@johng johng commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

Part of the free-threading docs tracking issue (gh-145912).

The only documentation of ThreadSanitizer was the one-line --with-thread-sanitizer entry in using/configure.rst. This adds a "Testing with ThreadSanitizer" section to the free-threading extensions HOWTO covering:

  • building a free-threaded interpreter with TSan (--disable-gil --with-thread-sanitizer)
  • how extensions built with that interpreter are instrumented, and that uninstrumented code is not checked
  • what a report looks like, and TSAN_OPTIONS / the suppressions file in Tools/tsan/
  • running CPython's TSan tests (--tsan, --tsan-parallel)
  • that TSan reports C-level data races, not logic races in Python code

using/configure.rst now links to it from --with-thread-sanitizer.

There was no documentation on using ThreadSanitizer with the free-threaded
build beyond the configure option. Describe how to build, how extensions are
instrumented, how to read a report, and how to run CPython's TSan tests, and
note that TSan does not detect logic races in Python code.
@johng

johng commented Nov 2, 2026

Copy link
Copy Markdown
Contributor Author

I can't say I'm an expert on using TSAN only using what has been required to find some FT bugs in the past (so maybe some better people to have raised/reviewed this), from what I can see this is correct and enough to get started though

The HOWTO sets the default highlight language to C, so the TSan report was
lexed as C and raised a highlighting warning. Mark it, and the shell
commands, with explicit languages.
@read-the-docs-community

read-the-docs-community Bot commented Nov 2, 2026 •

Copy link
Copy Markdown

Documentation build overview

📚 cpython-previews | 🛠️ Build #35590905 | 📁 Comparing 9ea1e7d against main (86be79a)

  🔍 Preview build  

2 files changed
± howto/free-threading-extensions.html
± whatsnew/changelog.html

Comment thread Doc/using/configure.rst Outdated
Enable ThreadSanitizer data race detector, ``tsan``
(default is no).
(default is no). It is most useful together with :option:`--disable-gil`.
See :ref:`freethreading-tsan`.

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.

This sentence is acutally needed?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I had made this in relation to FT but Doc/howto/free-threading-extensions.rst change should be enough of a reference?

@johng
johng requested a review from corona10 November 2, 2026 19:07
SUMMARY: ThreadSanitizer: data race racy.c:8 in bump
The TSan runtime can be configured with the ``TSAN_OPTIONS`` environment
variable, for example ``TSAN_OPTIONS="suppressions=path/to/suppressions.txt"``

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.

This feels like it belongs in https://devguide.python.org/development-tools/sanitizers/ instead, but I'll leave the decision up to the free-threading experts.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting review docs Documentation in the Doc dir skip news

Projects

Status: Todo

Development

Successfully merging this pull request may close these issues.

3 participants