Skip to main content

A stall tracker for Python's GIL and Trio tasks

Project description

Perpetuo

perpetuo, verb: To cause to continue uninterruptedly, to proceed with continually

Perpetuo is a stall tracker for Python. Specifically, it can detect when:

  • One thread is holding the GIL for too long, blocking other threads from having a chance to run (requires an instrumented version of CPython)

  • One Trio task is running too long without checkpointing, blocking other tasks from having a chance to run

The actual monitoring is done from a separate process, using a customized version of py-spy. So the monitoring is very low overhead and should not interfere with the monitored process at all. The goal is to be able to use this in production.

Quickstart

  1. pip install perpetuo

  2. Optional: patch CPython (see below)

  3. import perpetuo

  4. If you're using Trio: call perpetuo.dwim() inside trio.run

    If you're not using Trio: call perpetuo.dwim() anywhere

  5. Optional: log perpetuo.dwim()'s return value to see what it did

Available API

perpetuo.start_watcher(): Spawns the monitoring process in the background.

perpetuo.instrument_gil(): Enables GIL instrumentation, or raises RuntimeError if you don't have the patched version of CPython.

perpetuo.instrument_trio(): Enables Trio instrumentation. Must be called inside trio.run.

perpetuo.dwim(): Attempts to call all the above functions as appropriate, and returns a list of strings describing which operations it actually performed. If you're using Trio, make sure to call it inside trio.run.

StallTracker: Low-level class that allows you to add custom instrumentation to other things. See source for details.

Patching CPython to instrument the GIL

There are patches available for:

CPython version 3.10.*:

https://github.com/python/cpython/compare/3.10...njsmith:cpython:njs/perpetuo-gil.diff

CPython version 3.11:

https://github.com/python/cpython/compare/3.11...njsmith:cpython:njs/perpetuo-gil-3.11.diff

CPython version 3.12:

https://github.com/python/cpython/compare/3.12...njsmith:cpython:njs/perpetuo-gil-3.12.diff

Bonus

Niccolò Paganini's Moto Perpetuo, performed by Antal Zalai

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

perpetuo-0.7.3.tar.gz (33.1 kB view details)

Uploaded Source

Built Distributions

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

perpetuo-0.7.3-cp39-abi3-win_amd64.whl (1.5 MB view details)

Uploaded CPython 3.9+Windows x86-64

perpetuo-0.7.3-cp39-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl (2.5 MB view details)

Uploaded CPython 3.9+manylinux: glibc 2.17+ x86-64

perpetuo-0.7.3-cp39-abi3-macosx_10_12_universal2.whl (3.1 MB view details)

Uploaded CPython 3.9+macOS 10.12+ universal2 (ARM64, x86-64)

File details

Details for the file perpetuo-0.7.3.tar.gz.

File metadata

  • Download URL: perpetuo-0.7.3.tar.gz
  • Upload date:
  • Size: 33.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for perpetuo-0.7.3.tar.gz
Algorithm Hash digest
SHA256 51f72bb1fde668ec590efba2226d47c35b06c50cda547eb4e0a74fdddd6e6deb
MD5 c247532cda836c05c4f17d8bc72e9e3c
BLAKE2b-256 81b41a9d5c894ca2056eff300fe0815b132cf9cf073e9fa781d6079b345b02b8

See more details on using hashes here.

Provenance

The following attestation bundles were made for perpetuo-0.7.3.tar.gz:

Publisher: build_wheels.yml on njsmith/perpetuo

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

File details

Details for the file perpetuo-0.7.3-cp39-abi3-win_amd64.whl.

File metadata

  • Download URL: perpetuo-0.7.3-cp39-abi3-win_amd64.whl
  • Upload date:
  • Size: 1.5 MB
  • Tags: CPython 3.9+, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for perpetuo-0.7.3-cp39-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 ec547094a8708a4bfaf739f3cfc31d0ec2753465d1c5dcbb4345e4645a57c6b6
MD5 69e3298cae941b164366c847218d305c
BLAKE2b-256 8792432feca4fb8a15596f4d3907e4faa916cd95213478577ae5cff02fc93efe

See more details on using hashes here.

Provenance

The following attestation bundles were made for perpetuo-0.7.3-cp39-abi3-win_amd64.whl:

Publisher: build_wheels.yml on njsmith/perpetuo

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

File details

Details for the file perpetuo-0.7.3-cp39-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl.

File metadata

File hashes

Hashes for perpetuo-0.7.3-cp39-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Algorithm Hash digest
SHA256 f7899120e6eeafb7e66c25437443ecbcd61f6ea687d3bb2e13bc1a8747ee99d9
MD5 73845cced02397aec459195af1bcd20a
BLAKE2b-256 5bdf08f62722a2459e0595192f900f761df834823f3bf5372891c94e057a4e80

See more details on using hashes here.

Provenance

The following attestation bundles were made for perpetuo-0.7.3-cp39-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl:

Publisher: build_wheels.yml on njsmith/perpetuo

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

File details

Details for the file perpetuo-0.7.3-cp39-abi3-macosx_10_12_universal2.whl.

File metadata

File hashes

Hashes for perpetuo-0.7.3-cp39-abi3-macosx_10_12_universal2.whl
Algorithm Hash digest
SHA256 c28b6cd3222d18b8c31a2af3790f8aa82828e97182522a144a0ea37e14b9d9cf
MD5 36d6871cc36fb1493b59d3a9269fbe3d
BLAKE2b-256 dcf454bd1b6e7633c5ff3af632119522a4d5195befa92a9487dce8796694fb39

See more details on using hashes here.

Provenance

The following attestation bundles were made for perpetuo-0.7.3-cp39-abi3-macosx_10_12_universal2.whl:

Publisher: build_wheels.yml on njsmith/perpetuo

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