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
-
pip install perpetuo
-
Optional: patch CPython (see below)
-
import perpetuo
-
If you're using Trio: call
perpetuo.dwim()
insidetrio.run
If you're not using Trio: call
perpetuo.dwim()
anywhere -
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
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Hashes for perpetuo-0.1.0-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ab4216a5ba0a843840e013ecee8e926066b9653d1f0d5f23fb2f651c0e100ea1 |
|
MD5 | 1b94ae2739373e6a7e11bbf6d152c496 |
|
BLAKE2b-256 | 39d42a1316b81a9e71179f4bbe9625cf80dfb98a8ac2ab3268578616825aeefa |
Hashes for perpetuo-0.1.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2000d23167d6c8d61887c842601d3c1c5c6b34399c97ca02669fe7b2a061a835 |
|
MD5 | 5675c527dbe23211e2e777d3f254e337 |
|
BLAKE2b-256 | bcd3bc13b1ad2730a48999bb09c375c97955d5e7ab617ca06958c04826d8eb86 |
Hashes for perpetuo-0.1.0-cp39-cp39-macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bc9e9b8118e8a263d0fa8ecf9835494a11a5a5e34951b1818ab7363c7f1ec5f2 |
|
MD5 | 462afe0b36ffb2df784493c8961d85a6 |
|
BLAKE2b-256 | cf298247e11bfa7d0cd4491ffb0c76ba97a37cd16fa01dc7a2b5542fb332afaa |