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.2.tar.gz (34.2 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.2-cp39-abi3-win_amd64.whl (1.4 MB view details)

Uploaded CPython 3.9+Windows x86-64

perpetuo-0.7.2-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.9 MB view details)

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

perpetuo-0.7.2-cp39-abi3-macosx_10_12_universal2.whl (3.2 MB view details)

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

File details

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

File metadata

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

File hashes

Hashes for perpetuo-0.7.2.tar.gz
Algorithm Hash digest
SHA256 6e790a0c99f4d5f8ff5a8fb2e0ac78079ed2e03224ae0cbd1525d5a212ffde20
MD5 3ff7b38e3265823d655f2d2bdd82f779
BLAKE2b-256 7a45ee874519dfe8ab459b7cf252a45c56cce787c097252e6ff4ae43810798e0

See more details on using hashes here.

Provenance

The following attestation bundles were made for perpetuo-0.7.2.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.2-cp39-abi3-win_amd64.whl.

File metadata

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

File hashes

Hashes for perpetuo-0.7.2-cp39-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 160baa64fcbe9b1288acee40ae6e98e08aa235f2a54cb00d342229512d776308
MD5 ff69c33c972366f8cc114c3e4447a8bc
BLAKE2b-256 d2f2d8547b5eaca38a8ddcb4bc0e4062c686292f00804f32b069bc7d3a874bc6

See more details on using hashes here.

Provenance

The following attestation bundles were made for perpetuo-0.7.2-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.2-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for perpetuo-0.7.2-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 39767fc7857042fa859bffe2db67ccd0dae478c6380cd5c74b70940b748137a2
MD5 ed00c093bb7b39b0ae47380f87c2fd57
BLAKE2b-256 1c42d0cdb2983c45292cdbc926fbfa720e4a902a26ab5781796c539c87b918a7

See more details on using hashes here.

Provenance

The following attestation bundles were made for perpetuo-0.7.2-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_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.2-cp39-abi3-macosx_10_12_universal2.whl.

File metadata

File hashes

Hashes for perpetuo-0.7.2-cp39-abi3-macosx_10_12_universal2.whl
Algorithm Hash digest
SHA256 378b5fe9b0b899f909f8487adb8e2f0adaf50360cf37f2c2784201f791db2aef
MD5 3ebe6b01dc3390272cd61ab72d9e9f23
BLAKE2b-256 66b677f5961ae42f10a910ff57dde307824a7d05deaa32aa6c8a0dbad5675219

See more details on using hashes here.

Provenance

The following attestation bundles were made for perpetuo-0.7.2-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