SiginfoBasic
SiginfoBasic is the most basic class for SigInfo. It prints the current call stack to its output
SiginfoBasic class
- class siginfo.siginfoclass.SiginfoBasic(info=True, usr1=True, usr2=False, output=None)[source]
Base class for the SigInfo module
- Parameters:
info (bool) – Listen for SIGINFO Default: True (works only on Mac and BSD)
usr1 (bool) – Listen for SIGUSR1 Default: True
usr2 (bool)) – Listen for SIGUSR2 Default: True
output (_io.TextIOWrapper) – IO interface for writing output and log. Default: sys.stdout
- COLUMNS
Width of Terminal (number of columns) Default: Auto (Fallback to 80)
- Type:
int
- MAX_LEVELS
Number of parent stack frames to display Default: 0 (only current frame)
- Type:
int
- Returns:
SigInfoBasic
- Return type:
An instance of the class
Example
foo = SiginfoBasic() # Write up to 120 characters per line foo.COLUMNS = 120 # Write three parent stack frame foo.MAX_LEVELS = 3 # create executeable to send signal to Python script foo.create_info_script('/usr/local/bin') # Code of your regular Python script def read_lines(): a = 12 b = 15 i = 0 print('Loading a very long file') with open('many_rows.txt') as fh: for line in fh: i += 1 # print(line) time.sleep(1) print('Done loading') # Some useless function so we have more stacks def main2(): read_lines() def main(): main2() if __name__ == '__main__': main()
In another terminal window:
# send signal via custom script /usr/local/bin/siginfo-USR1 # Output: ======================================================================================================================== 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> ======================================================================================================================== ...
- create_info_script(path=None, prefix='', overwrite=False)[source]
Create an executable on the file system to send the appropiate signal.
For user convenience, create executable filess in the specified path that can be used to send corresponding signals to the parent’s script.
- Parameters:
path (str) – path to executable files (default $HOME)
prefix (str) – Prefix of the executable file name (default ‘’)
overwrite (bool) – Overwrite existing executables (default False)
- Return type:
None