项目作者: wagoodman

项目描述 :
A python module which can be used to interrupt a script and inspect running objects or self destruct a run-away script
高级语言: Python
项目地址: git://github.com/wagoodman/PyDebugShell.git
创建时间: 2014-08-28T20:04:39Z
项目社区:https://github.com/wagoodman/PyDebugShell

开源协议:

下载


PyDebugShell

A python module which can be used to interrupt a script and inspect running objects or self destruct a run-away script

Strike Ctrl+\ during execution of any python script which utilizes this module to get to an interactive pythgon shell and inspect local/global objects:

  1. ===[ COMMANDS ]===
  2. List Objects:
  3. report
  4. report more
  5. dir()
  6. locals()
  7. globals()
  8. Inspect a specific object:
  9. debug.ObjSize.getSize( obj )
  10. debug.showObj( obj )
  11. Process Information:
  12. proc
  13. Test the self destruct:
  14. stress test
  15. -----------------------------------------------------------------
  16. Debug Shell.
  17. >>>

Import the debug module and add a specific try/except anywhere in your code:

  1. import debug
  2. import time
  3. def main():
  4. try:
  5. while True:
  6. ...
  7. ...
  8. except debug.DebugException:
  9. exec debug.normalHandler
  10. except debug.SelfDestructException, message:
  11. print message
  12. finally:
  13. debug.selfDestructThread.stop()
  14. debug.selfDestructThread.join()

Or use the given decorator on a long running method:

  1. @debug.DebugSession(globals())
  2. def main():
  3. ...
  4. ...
  5. main()

If the CPU utilization goes beyond 10% for a long enough duration, or memory utilization spikes above 1024MB then
the process will automatically killed and show this message:

  1. Proc 19008 killed because it took up too many resources!
  2. CPU Percent [Cur/Avg/Threshold]: 17.7 / 4.25 / 10.0
  3. Mem KBytes [Cur/Avg/Threshold]: 180612.0 / 102968.8 / 102400.0

This is not production worthy! Please only use this while developing.