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

Currently the patch is only available for CPython version 3.10.*. It can be downloaded here:

https://github.com/python/cpython/compare/3.10...njsmith:cpython:njs/perpetuo-gil.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.6.0.tar.gz (32.6 kB view details)

Uploaded Source

Built Distributions

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

Uploaded CPython 3.9+ Windows x86-64

perpetuo-0.6.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.3 MB view details)

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

perpetuo-0.6.0-cp39-abi3-macosx_10_9_universal2.whl (3.1 MB view details)

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

File details

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

File metadata

  • Download URL: perpetuo-0.6.0.tar.gz
  • Upload date:
  • Size: 32.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for perpetuo-0.6.0.tar.gz
Algorithm Hash digest
SHA256 4806c846fea3aeffdccb4d62d0215854bad0e3f5d3ac194bde512d4dd4943239
MD5 7d47628fb10401f6d0ea273ba4dbbe65
BLAKE2b-256 554eec43d7c68009c52394cff49d004ef4e5d63ffad4b6854d0212e3772141a3

See more details on using hashes here.

File details

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

File metadata

  • Download URL: perpetuo-0.6.0-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/5.1.1 CPython/3.12.7

File hashes

Hashes for perpetuo-0.6.0-cp39-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 f90d336c225c28f8a5db8919ec1f9c7624e343f88b9f7a8bb54b6ea63ef52c6e
MD5 7914d56ab5b10fd84630e7b8883bcb18
BLAKE2b-256 37a50e9646b5543692c261bd95f140092ac40cd2d7bb824a6186c8115d462a05

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for perpetuo-0.6.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 d0d7c4efcbd1a57ebf1b98b9b080564115afb48700a9fc61d674324ba813d443
MD5 c8d2226a11c39f981e6e117968f97547
BLAKE2b-256 64e9993a9bf7bda37b980a7f886c7b48b7e44e763f53c76fb5bc5d2503fe96dc

See more details on using hashes here.

File details

Details for the file perpetuo-0.6.0-cp39-abi3-macosx_10_9_universal2.whl.

File metadata

File hashes

Hashes for perpetuo-0.6.0-cp39-abi3-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 1f00febbeb8a5630a10b7f6a80d7334dd78eb6b4acae8c9a8b4b7b01347d1e3b
MD5 861ddb8acff76bff4152a8a43dd43927
BLAKE2b-256 935422696973680a7d2f89b90b7d1d6a58e4b4ed157e0293803080dbafe52995

See more details on using hashes here.

Supported by

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