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.1.tar.gz (32.6 kB view details)

Uploaded Source

Built Distributions

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

Uploaded CPython 3.9+ Windows x86-64

perpetuo-0.6.1-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.1-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.1.tar.gz.

File metadata

  • Download URL: perpetuo-0.6.1.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.1.tar.gz
Algorithm Hash digest
SHA256 6323c87102eef2f07304ab594c8d13fb33745f19c27f0d3819211bb8713d8e6c
MD5 d1621ad4219a22bd1161023bfa516e88
BLAKE2b-256 bbf7985af0c11891f13bbd1054dc8f4d216311f9889cc95f0c5d0224893aa8a6

See more details on using hashes here.

File details

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

File metadata

  • Download URL: perpetuo-0.6.1-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.1-cp39-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 834c5a83b9d5cea45211001135b7a7dc8051f9fda695326f20d4618d7a57ae63
MD5 6f0a8bb679d94eb01e0a988cc671fc0a
BLAKE2b-256 a23f8fd93266a68c6faf80d04e0a5efef5bbd52e21656d089033ef658c16bd2f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for perpetuo-0.6.1-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 316cfa43e12335a4b7d7f7ce4a497334c6c12ba456d15de8a2f7d7390a3be700
MD5 944a71a75300a87272398e01f2ee7c62
BLAKE2b-256 18d0023e048ea9fa8de1d349980a7bb1b1a9283e20e8dea1b474529df56c250f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for perpetuo-0.6.1-cp39-abi3-macosx_10_9_universal2.whl
Algorithm Hash digest
SHA256 effb1c69635cd977e12544eed385aace4971b7d7b6ba752e23d7ae672cf15783
MD5 116265976f277841896d491fe55a2d8b
BLAKE2b-256 0410f76df2a5836012f7e60b723556822c30193835e19e47630932f522236cbd

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