siginfo is a small Python module to conveniently get status or debug info from running Python processes.
siginfo listens for SIGUSR1 or SIGUSR2 [1] signals and prints info about the current callstack, local variables etc.
Use cases
You have long running Python processes and want to check in on progress, but don’t want to print the progress all the time. This is especially useful for I/O heavy operations.
Imagine you’re reading in a large file and work on it line by line. Instead of printing the line-number in regular intervals, you can simply send a SIGUSR command from another shell session and see the current callstack or start an interactive debugger.
How to
Simply add the following two lines:
from siginfo import SiginfoBasic
SiginfoBasic()
to your python script. Once your application is running, you can always check the current callstack from another shell session by sending a SIGUSR signal.
kill -SIGUSR1 ${pid}
It will now print the current callstack with basic information about all local variables to stdout (or a predefined file).
========================================================================================================================
LEVEL 0
METHOD read_lines
LINE NUMBER: 33
------------------------------------------------------------------------------------------------------------------------
LOCALS
VARIABLE | TYPE | VALUE
i | int | 1
fh | TextIOWrapper | <_io.TextIOWrapper name='many_rows.txt' mode='r' encoding='UTF-8'>
b | int | 15
a | int | 12
line | str | Row 1
------------------------------------------------------------------------------------------------------------------------
SCOPE <code object read_lines at 0x108c30c90, file "long_script.py", line 24>
CALLER <code object main2 at 0x108c309c0, file "long_script.py", line 21>
========================================================================================================================
========================================================================================================================
LEVEL 1
METHOD main2
LINE NUMBER: 22
------------------------------------------------------------------------------------------------------------------------
LOCALS
VARIABLE | TYPE | VALUE
------------------------------------------------------------------------------------------------------------------------
SCOPE <code object main2 at 0x108c309c0, file "long_script.py", line 21>
CALLER <code object main at 0x108c30ed0, file "long_script.py", line 18>
========================================================================================================================
...
Installation
You can install siginfo via pip
pip install siginfo
Usage
Include siginfo in your python script
import siginfo
Initialize SignInfo Class
siginfo.SiginfoBasic()
Basic overview
siginfo contains the following classes:
SiginfoBasic Print info about the current stack (and caller stacks). Regular execution continues automatically.
SigInfoPDB Open the PDB debugger. Pauses script execution until debugger is exited.
SigInfoSingle Print the value of a single variable of the current scope. Continues regular execution automatically.
Initiating the class
All class allow the following arguments:
info Listen for SIGNFO (Default: True) (only on Mac and BSD)
usr1 Listen for SIGUSR1 (Default: True)
usr2 Listen for SIGUSR2 (Default: False)
output Where to write the output to (Default: sys.stdout). Can be anything that offers a write function.
from siginfo import SiginfoBasic
SiginfoBasic(info=True, usr1=False) # listen only for SIGINFO
SiginfoBasic(info=False, usr=True) # listen only for SIGUSR1
SiginfoBasic(output=open('mylog.log', 'a')) # Write call stack output to a log file
signinfo class instance attributes
COLUMNS: Maximum width of the Terminal (or max number of rows per line in an output file) (Default: current tty columns - 20; Fallback to 80 if determination isn’t possible)
MAX_LEVELS: Number of stack frames to print (Default: 1 [only the current one])
OUTPUT: Same as output argument to the constructor function. Defines where to write the output to (Default: sys.stdout)
from siginfo import SiginfoBasic
info_handler = SiginfoBasic()
info_handler.COLUMNS = 200 # Format output to match 200 columns
info_handler.MAX_LEVELS = 4 # Print the current frame + 3 parent frames
info_handler.OUTPUT = open('mylog.log', 'a') # write the output to mylog.log
API docs
For a more detailed API description, check out the full documentation
Footnotes
Metadata
Release files for siginfo 0.10
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| siginfo-0.10.tar.gz | 12.3 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| siginfo-0.10-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 21.2 kB
Release files / siginfo-0.10.tar.gz
| Download URL | siginfo-0.10.tar.gz |
|---|---|
| Size | 12.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
c33e952792e98eb5409e50a2bf8edfc318548542abaa49ae03f1d5e4fff7b0d6
|
|
BLAKE2b-256 checksum How to use checksums |
de897818e27077ac63ca1eafbe966d6cae7ac2349cf8f3fb586ba48981e0f2c2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.9.18
|
Release files / siginfo-0.10-py3-none-any.whl
| Download URL | siginfo-0.10-py3-none-any.whl |
|---|---|
| Size | 8.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
bf635d25f0f391df644b74a3de866c5537563f0d7ab9f0e196f1ba877ace998c
|
|
BLAKE2b-256 checksum How to use checksums |
792e64ca59cf84f0167b68c232ad22592dfa213c73253706fac81e1f65fd5625
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.9.18
|
Security for siginfo 0.10
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.