Skip to main content

Assorted debugging facilities.

Latest release 20241005:

  • New log_via_print(msg, *args[, file=stdout]) function to use cs.upd.print as a logging call.
  • @trace: new $CS_DEBUG_TRACE envvar which may be "print" or "warning" or "X".
  • New @abrk decorator to intercept AssertionError, NameError and RuntimeError and call breakpoint.

If the environment variable $CS_DEBUG_BUILTINS is set to a comma separated list of names then the builtins module will be monkey patched with those names, enabling trite debug use of those names anywhere in the code provided this module has been imported somewhere.

The allowed names are the list cs.debug.__all__ and include:

  • X: cs.x.X
  • abrk: a decorator to call breakpoint(0 in an AssertionError
  • pformat: pprint.pformat
  • pprint: pprint.pprint
  • print: cs.upd.print
  • r: cs.lex.r
  • redirect_stdout: contextlib.redirect_stdout
  • s: cs.lex.s
  • stack_dump: dump current Thread's call stack
  • thread_dump dump the active Threads with their call stacks
  • trace: the @trace decorator $CS_DEBUG_BUILTINS can also be set to "1" to install all of __all__ in the builtins.

abrk(*da, **dkw)

A decorator to intercept certain exceptions (by default AssertionError, NameError, RuntimeError) and call breakpoint(). The breakpoint frame contains:

  • func: the wrapper function
  • func_a, func_kw: the function positional and keyword arguments

stack_dump(stack=None, limit=None, logger=None, log_level=None)

Dump a stack trace to a logger.

Parameters:

  • stack: a stack list as returned by traceback.extract_stack. If missing or None, use the result of traceback.extract_stack().
  • limit: a limit to the number of stack entries to dump. If missing or None, dump all entries.
  • logger: a logger.Logger ducktype or the name of a logger. If missing or None, obtain a logger from logging.getLogger().
  • log_level: the logging level for the dump. If missing or None, use cs.logutils.loginfo.level.

thread_dump(Ts=None, fp=None)

Write thread identifiers and stack traces to the file fp.

Parameters:

  • Ts: the Threads to dump; if unspecified use threading.enumerate().
  • fp: the file to which to write; if unspecified use sys.stderr.

Class TimingOutLock

A Lock replacement which times out, used for locating deadlock points.

trace(*da, **dkw)

Decorator to report the call and return of a function.

Decorator parameters:

  • call: trace the call, default True
  • retval: trace the return, default False
  • exception: trace raised exceptions, default True
  • use_pformat: present the return value using pformat instead of repr, default False
  • with_caller: include the caller if this function, default False
  • with_pfx: include the current Pfx prefix, default False

Release Log

Release 20241005:

  • New log_via_print(msg, *args[, file=stdout]) function to use cs.upd.print as a logging call.
  • @trace: new $CS_DEBUG_TRACE envvar which may be "print" or "warning" or "X".
  • New @abrk decorator to intercept AssertionError, NameError and RuntimeError and call breakpoint.

Release 20240630: Assorted updates.

Release 20240519: trace_caller: access frame.name instead of frame.funcname.

Release 20240423:

  • Support "import *" by populating all with X, r, s, TimingOutLock, thread_dump, stack_dump, trace.
  • @trace: include the elapsed time on the return/exception log message.

Release 20230613.1: Bugfix builtins monkey patch.

Release 20230613: Honour $CS_DEBUG_BUILTINS envvar to monkey patch the builtins module, constraints via a white list.

Release 20230610:

  • DebuggingRLock fixes.
  • Move @trace from cs.py.func to cs.debug.
  • Drop Lock and RLock alias factories - importers should just use the debugging lock classes directly.
  • Rename threading.Thread to threading_Thread.
  • Simplify the debugging lock classes.

Release 20221118: stack_dump: cope when cs.logutils.setup_logging not run yet.

Release 20211208: @trace moved to cs.pyfunc, other minor changes.

Release 20200318: Remove use of cs.obj.O, universally supplanted by types.SimpleNamespace.

Release 20181231:

  • New TimingOutLock for locating deadlock points, grew from debugging cs.vt.index.
  • Other minor changes.

Release 20171231:

  • Update imports for recentchanges.
  • New context manager TraceSuite to trace start and end of a code suite.

Release 20160918: selftest(): fix parameter ordering to match unittest.

Release 20160828: Update metadata with "install_requires" instead of "requires".

Release 20160827:

  • New openfiles() to return selected pathnames of open files via lsof(8).
  • New selftest() to invoke unittests with benefits.
  • DebugShell, a cmd.Cmd subclass for debugging - current use case calls this with self.dict in a test case tearDwon.
  • debug_object_shell: convenience wrapper for DebugShell to call it on an object's attributes.

Release 20150116: PyPI prep.

Metadata

Release files for cs-debug 20241005

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for cs-debug 20241005
File Size Uploaded Provenance Actions
cs_debug-20241005.tar.gz 12.2 kB Without provenance Details for cs_debug-20241005.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for cs-debug 20241005
File Interpreter ABI Platform Actions
cs.debug-20241005-py3-none-any.whl Python 3 none any Details for cs.debug-20241005-py3-none-any.whl

Total release size: 23.4 kB

Release files / cs_debug-20241005.tar.gz

Download URL cs_debug-20241005.tar.gz
Size 12.2 kB
Tags Source
SHA-256 checksum
How to use checksums
f70abfb1cac9b4925633dbf6140010646a4a36733b2dd814df708ec79c7eaec8
BLAKE2b-256 checksum
How to use checksums
6f3acb53741788edd5ea34b9e6e4d9b8cfe89142c03d2333073af5ca830505ad
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.12.0

Release files / cs.debug-20241005-py3-none-any.whl

Download URL cs.debug-20241005-py3-none-any.whl
Size 11.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2368a70eaca4d133c1a91d7f9c73e7900007c69675d51335d5a848ff2de5e4b4
BLAKE2b-256 checksum
How to use checksums
3f21694f2961d9743cd055899a7957142f16936fac39c2e9c4261443dadf8e98
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.12.0

Security for cs-debug 20241005

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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page