Skip to main content

VerifiedFT: a precise dynamic data race detector for free-threaded Python

Project description

PyVFT — VerifiedFT for free-threaded Python

PyVFT is a pure-python precise dynamic data race detector for free-threaded CPython (PEP 703, 3.14+). It implements the VerifiedFT algorithm (Wilcox & Freund, PPoPP '18), adapted to the runtime semantics of Python's no-GIL build.

Through benchmarking with python-threading-benchmarks, expect a ~x slowdown and 3.9x memory overhead. See benchmarks/results/results.md for more information.

Requirements

  • Python 3.14 free-threaded build. PyVFT relies on the free-threaded interpreter for true threading. pyvft will still run on the GIL build but won't surface races prevented by the GIL.

Install

From PyPI

pip install pyvft
# or, with uv:
uv add pyvft

Usage

Run any script under the detector

uv run python -m pyvft path/to/script.py [script args...]

This AST-rewrites the entry script and every module it subsequently imports (excluding the stdlib and PyVFT itself) so attribute reads / writes / subscripts call into the race-detection engine. When the script exits, PyVFT prints a race report to stderr.

Try it on the included demos:

uv run python -m pyvft demo/counter_race.py        # WW race expected
uv run python -m pyvft demo/counter_locked.py      # no races expected
uv run python -m pyvft demo/fork_join_safe.py      # no races expected

See demo/README.md for the full demo index.

Choosing a VerifiedFT variant

The Wilcox & Freund paper presents two analyses, both verified race-precise. PyVFT implements both:

Version Storage per variable Race check Use it when
v1 full VectorClock for the last write and the union of reads element-wise vc_leq you want the simpler reference analyser (matches the paper's idealised algorithm)
v2 single Epoch for the last write; compressed ReadBottom → ReadEpoch → ReadVC state machine for reads constant-time epoch comparison in the common cases default; matches the optimised FastTrack analyser, ~O(1) per access on the fast path

Both versions detect the same set of data races on the same execution. v2 is the default everywhere; pick v1 with the --version flag or the version= kwarg:

uv run python -m pyvft --version v1 demo/counter_race.py
import pyvft

with pyvft.context(version="v1"):
    import workload
    workload.run()

@pyvft.detect(version="v1")
def test_concurrent():
    import workload
    workload.do_stuff()

pyvft.install(version="v1")

Embed the detector around a region of your own code

import pyvft

with pyvft.context():
    import workload          # auto-traced by the import hook
    workload.run()

Or as a decorator:

@pyvft.detect
def test_concurrent():
    import workload
    workload.do_stuff()

The detector is installed on enter and uninstalled on exit, and a race report is printed automatically. Note that modules imported BEFORE pyvft.install() (or before entering the context) are not retroactively instrumented. Keep the workload in a module imported inside the scope, or run the whole program under python -m pyvft.

Public API

pyvft.install(version="v2")     install the detector (monkey-patches + import hook)
pyvft.uninstall()               remove patches; race log is preserved
pyvft.context(version="v2")     context manager: install on enter, report on exit
@pyvft.detect                   decorator equivalent of pyvft.context() around a function
@pyvft.detect(version="v1")     decorator with an explicit analyser variant
pyvft.report(file=...)          print the race report
pyvft.races()                   list[RaceReport] for programmatic inspection
pyvft.reset()                   clear the race log; detector keeps running
pyvft.get_engine()              the active Engine instance (advanced)

References

  • Cormac Flanagan and Stephen N. Freund. FastTrack: Efficient and Precise Dynamic Race Detection. PLDI 2009.
  • James R. Wilcox, Cormac Flanagan, Stephen N. Freund. VerifiedFT: A Verified, High-Performance Precise Dynamic Race Detector. PPoPP 2018.
  • PEP 703 — Making the Global Interpreter Lock Optional in CPython.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyvft-0.2.0.tar.gz (2.2 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pyvft-0.2.0-py3-none-any.whl (29.8 kB view details)

Uploaded Python 3

File details

Details for the file pyvft-0.2.0.tar.gz.

File metadata

  • Download URL: pyvft-0.2.0.tar.gz
  • Upload date:
  • Size: 2.2 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for pyvft-0.2.0.tar.gz
Algorithm Hash digest
SHA256 9fb858b1ca88ddfb2ddf4de86bc14954c803c214a94c8a97dbc65ad8c1f7b924
MD5 32ac37c7dc5ed00e7aa66aec2545e98c
BLAKE2b-256 c874800c6adc4ba1832c6ec3aa89d75aa8f57d6bf25093e1c259be98f1d5c7ce

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyvft-0.2.0.tar.gz:

Publisher: publish.yaml on Alvicorn/pyVFT

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pyvft-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: pyvft-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 29.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for pyvft-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ec395d756a81bf78adf14a10de16da9a36df361c09927adac44949f7a85f2b00
MD5 7ef2b21319a946c1728c03d74a47e75b
BLAKE2b-256 afd5d994e3304ef373c29e9fef0c30581f68f2514a0b95576b3bd243818b1173

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyvft-0.2.0-py3-none-any.whl:

Publisher: publish.yaml on Alvicorn/pyVFT

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page