Skip to main content

Assorted debugging facilities.

Project description

Assorted debugging facilities.

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

Function DEBUG(f, force=False)

Decorator to wrap functions in timing and value debuggers.

Function debug_object_shell(o, prompt=None)

Interactive prompt for inspecting variables.

Class DebuggingLock(DebugWrapper, types.SimpleNamespace)

Wrapper class for threading.Lock to trace creation and use.

cs.threads.Lock() returns one of these in debug mode or a raw threading.Lock otherwise.

Class DebuggingRLock(DebugWrapper, types.SimpleNamespace)

Wrapper class for threading.RLock to trace creation and use.

cs.threads.RLock() returns on of these in debug mode or a raw threading.RLock otherwise.

Class DebugShell(cmd.Cmd)

An interactive prompt for python statements, attached to /dev/tty by default.

Class DebugWrapper(types.SimpleNamespace)

Base class for classes presenting debugging wrappers.

Function DF(func, *a, **kw)

Wrapper for a function call to debug its use.

This requires rewriting the call from f(*a,*kw) to DF(f,*a,**kw). Alternatively one could rewrite as DEBUG(f)(*a,**kw).

Class Lock(DebugWrapper, types.SimpleNamespace)

Wrapper class for threading.Lock to trace creation and use.

cs.threads.Lock() returns one of these in debug mode or a raw threading.Lock otherwise.

Function openfiles(substr=None, pid=None)

Run lsof(8) against process pid returning paths of open files whose paths contain substr.

Parameters:

  • substr: default substring to select by; default returns all paths.
  • pid: process to examine; default from os.getpid().

Class RLock(DebugWrapper, types.SimpleNamespace)

Wrapper class for threading.RLock to trace creation and use.

cs.threads.RLock() returns on of these in debug mode or a raw threading.RLock otherwise.

Function selftest(module_name, defaultTest=None, argv=None)

Called by my unit tests.

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.

Function trace_caller(func)

Decorator to report the caller of a function when called.

Class TraceSuite

Context manager to trace start and end of a code suite.

Release Log

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-20230610.tar.gz (9.7 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-20230610-py3-none-any.whl (8.8 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for cs.debug-20230610.tar.gz
Algorithm Hash digest
SHA256 06cedb68a9ff82868ec2f4e0729ef1955153a0cdb7ea2281219dc96a3e817fb0
MD5 6476ebf67fd246841c9fef217972b2f2
BLAKE2b-256 a212c719c9bf0ec43d61276cc1a2072eeb1b58f5303c6e27740ca29a020f070a

See more details on using hashes here.

File details

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

File metadata

  • Download URL: cs.debug-20230610-py3-none-any.whl
  • Upload date:
  • Size: 8.8 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-20230610-py3-none-any.whl
Algorithm Hash digest
SHA256 d0a637dc70f839c5fb1bdee0d1f5fb8e4a897aac5234e71129946cc9f7db16e4
MD5 1b10974ffa1e839a2e8b26f88c766f62
BLAKE2b-256 ae9252386d79ee2d753f38b716067739b59fe2d63bff2be7bd77d42013d1458e

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