Functions to neatly print debug information to the terminal output, well-suited for multithreaded programs.
Project description
DvG_debug_functions
Provides functions for printing debug information to the terminal output.
print_fancy_traceback(err=None, back: int = 3, show_full_paths: bool = False)
Print the exception or the current regular call-stack traceback to the terminal, using ANSI color codes that mimic the IPython command shell.
- Args:
- err (Exception | str | None, optional):
When err is of type Exception, then an exception traceback will be printed. When err is of another type, then the current regular call-stack traceback will be printed.
Default: None
- back (int, optional):
Depth of the traceback to print.
Default: 3
- show_full_paths (bool, optional):
Shows the full filepath in the traceback when True, otherwise just the filename.
Default: False
Example output:
dprint(str_msg: str, ANSI_color: str = None)
‘Debug’ print a single line to the terminal with optional ANSI color codes. The line will be terminated with a newline character and the terminal output buffer is forced to flush before and after every print. In addition, if PyQt5 is present in the Python environment, then a mutex lock will be obtained and released again for each dprint execution.
There is a lot of overhead using this print statement, but it is particularly well-suited for multithreaded PyQt programs where multiple threads are each printing information to the same terminal. The dprint() function ensure that each line sent to the terminal will remain as a continious single line, whereas a regular print() statement will likely result in the lines getting mixed up.
tprint(str_msg, ANSI_color: str = None)
Identical to dprint(), but now prepended with a time.perf_counter() timestamp.
ANSI
class ANSI: NONE = "" RED = "\033[1;31m" GREEN = "\033[1;32m" YELLOW = "\033[1;33m" BLUE = "\033[1;34m" PURPLE = "\033[1;35m" # aka MAGENTA MAGENTA = "\033[1;35m" CYAN = "\033[1;36m" WHITE = "\033[1;37m"
Changelog
2.1.1 (2020-07-18)
Added flag show_full_paths to print_fancy_traceback()
2.1.0 (2020-07-17)
Improved print_fancy_traceback()
2.0.0 (2020-07-02)
DvG module filenames changed to lowercase
1.1.2 (2020-06-08)
Code style: black
1.1.1 (2020-06-06)
Extended README
1.1.0 (2020-06-04)
Added tprint(…)
0.0.1 (2020-05-13)
First release on PyPI.
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 Distribution
Hashes for dvg-debug-functions-2.1.1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5c46b9bec0d6a7758c3becec2e8e4a274f308aa471f778b36786aa51bd8bf266 |
|
MD5 | 49c56fe662b14280c770b2f0c82822c6 |
|
BLAKE2b-256 | d078147a27f664b35f428290f5446b29c6b3c0af1e1aab114126ff9e3062e865 |
Hashes for dvg_debug_functions-2.1.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f0393b58b2a530c6eb31814abad054315fc11fbd4480b756036d13db22b7a1f6 |
|
MD5 | 233275a0e2ced428ea150900a34272b9 |
|
BLAKE2b-256 | cc21f4358f92a547ae811706ec9f3b8ca1c1dbbfe575916ee57604d32150cfc5 |