X-Git-Url: http://dolda2000.com/gitweb/?p=pdm.git;a=blobdiff_plain;f=pdm%2Futil.py;fp=pdm%2Futil.py;h=53cc82a6043a3c910f80bf2167cc6f51236cd3b8;hp=0000000000000000000000000000000000000000;hb=342c8c21078cb74025b2f242b3649628a96ccb1d;hpb=1a8ebe554dad381da2df0200b50a9c9f676d84c2 diff --git a/pdm/util.py b/pdm/util.py new file mode 100644 index 0000000..53cc82a --- /dev/null +++ b/pdm/util.py @@ -0,0 +1,16 @@ +"""Python Daemon Management -- Miscellaneous utilities + +This module contains various functions that may be useful to call from +the PDM REPL. +""" + +import sys, traceback, threading + +def threads(): + "Returns a dict of currently known threads, mapped to their respective frames." + tt = dict((th.ident, th) for th in threading.enumerate()) + return dict((tt.get(key, key), val) for key, val in sys._current_frames().iteritems()) + +def traces(): + "Returns the value of threads() with each frame expanded to a backtrace." + return dict((th, traceback.extract_stack(frame)) for th, frame in threads().iteritems())