Skip to main content

Assorted debugging facilities.

Project description

Assorted debugging facilities.

Latest release 20240630: Assorted updates.

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
  • breakpoint: cs.upd.breakpoint
  • 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.

Function 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.

Function 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.

Function 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 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.

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

cs.debug-20240630.tar.gz (11.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

cs.debug-20240630-py3-none-any.whl (10.7 kB view details)

Uploaded Python 3

File details

Details for the file cs.debug-20240630.tar.gz.

File metadata

  • Download URL: cs.debug-20240630.tar.gz
  • Upload date:
  • Size: 11.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.6

File hashes

Hashes for cs.debug-20240630.tar.gz
Algorithm Hash digest
SHA256 9fbbe8653cf1420598d551b42f2a9aa99bee630587187856f82595ec86f339a6
MD5 86e2c3b35192b62fe5b3f86a1f0b9cdd
BLAKE2b-256 3992994fde4fb167a5c5ca1ce99822a23ca46742c46459d6e4d857c9dcd5cff3

See more details on using hashes here.

File details

Details for the file cs.debug-20240630-py3-none-any.whl.

File metadata

  • Download URL: cs.debug-20240630-py3-none-any.whl
  • Upload date:
  • Size: 10.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.6

File hashes

Hashes for cs.debug-20240630-py3-none-any.whl
Algorithm Hash digest
SHA256 6da87baa462d85e319e68dc63f784b4180970c2bfb6fcb93e30a5ae369e4ef73
MD5 ec00b2f5c80eefa4c91d02d81c998b53
BLAKE2b-256 b8651a01ef5a2d058d50134dc1cc7268379dad09c64603182126f604b08cfc1d

See more details on using hashes here.

Supported by

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