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.4.0-cp39-abi3-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2e726a9cb6cc92d4b0b421e7d89ea50ef09941c2665ebe0fb158e3de0d0bd483 |
|
MD5 | 395563d00d232c43fdb3274ab5715b16 |
|
BLAKE2b-256 | 34bde3c40eef5b73b80b475e9f0239cadec37f8a0e0ae9d4d25b8c34865be9f9 |
Hashes for perpetuo-0.4.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e33e92eb0e9a360b9a4d8ebc479b1c53b8bddba4f49ba022457b010ee45c3098 |
|
MD5 | 6441e8c470f3e57b661b81bb71428aa2 |
|
BLAKE2b-256 | 390c97e2cb9e1a387a9bf2f758285a7c81d7a19f7af50b9b2ec50f81167b1521 |
Hashes for perpetuo-0.4.0-cp39-abi3-macosx_10_9_universal2.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b783970138667b50429e1e5377cda661bd69907f066a4c8079cc299aa2a039a3 |
|
MD5 | 35d5d035ff8472cd496ed277418322b7 |
|
BLAKE2b-256 | 2bd1ebe4199521f413086bc816a884f242ceb1910b95a2f124f355aaf2ce9827 |