Skip to main content

Provides functions for neatly printing debug information to the terminal output, well-suited for multithreaded programs.

Project description

https://img.shields.io/pypi/v/dvg-debug-functions https://img.shields.io/pypi/pyversions/dvg-debug-functions https://github.com/Dennis-van-Gils/python-dvg-debug-functions/actions/workflows/python-package.yml/badge.svg https://img.shields.io/badge/code%20style-black-000000.svg https://img.shields.io/badge/License-MIT-purple.svg

DvG_debug_functions

Provides functions for neatly printing debug information to the terminal output, well-suited for multithreaded programs.

Supports PyQt5, PyQt6, PySide2 and PySide6.

Installation:

pip install dvg-debug-functions

API

Functions

  • 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:

    images/print_fancy_traceback.png
  • dprint(str_msg: str, ANSI_color: str = None)

    ‘Debug’ print a single line to the terminal with optional ANSI color codes. 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.

    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.

  • tprint(str_msg: str, ANSI_color: str = None)

    Identical to dprint(), but now prepended with a time.perf_counter() timestamp.

Classes

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.4.0 (2022-09-13)

  • Neater support for PyQt5, PyQt6, PySide2 and PySide6

  • Migrated from travis to Github actions

2.2.0 (2022-09-13)

  • Added support for PyQt5, PyQt6, PySide2 and PySide6

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

dvg-debug-functions-2.4.0.tar.gz (20.3 kB view details)

Uploaded Source

Built Distribution

dvg_debug_functions-2.4.0-py3-none-any.whl (6.6 kB view details)

Uploaded Python 3

File details

Details for the file dvg-debug-functions-2.4.0.tar.gz.

File metadata

  • Download URL: dvg-debug-functions-2.4.0.tar.gz
  • Upload date:
  • Size: 20.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.9

File hashes

Hashes for dvg-debug-functions-2.4.0.tar.gz
Algorithm Hash digest
SHA256 25f0c9c6d9514e8d7fd6cdc6f737c3d4763d82b52b76861e4b50532fe53e605f
MD5 6f4b41722ff455c8aa07ded023a51435
BLAKE2b-256 a382b17000ab37fdb96a32f9a2705bcfbde0fae1a10aeb95d3ffeb4392448e43

See more details on using hashes here.

File details

Details for the file dvg_debug_functions-2.4.0-py3-none-any.whl.

File metadata

File hashes

Hashes for dvg_debug_functions-2.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a8ff4a7fca132f60edc7393f594e16af7336d995b6635f7ab605f8bd5660229b
MD5 c5d9b2393b0a338400bbd736d3c7b671
BLAKE2b-256 06c62b0d5d3091d7722cee0062c1031054a3404ac9891f1a14a76f501a94c61b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page