Python error logging -


i'd find way log every error forces python interpreter quit saved file being printed screen. reason want keep stats on types of errors make while writing code, eye towards finding ways avoid mistakes make commonly in future.

i've been attempting writing wrapper python interpreter using subprocess module. basically, runs python interpreter, captures output, parse , saves file, prints output, , use matplotlib make summary figures. however, i'm having problem getting output wrapper script in real time. example, if script i'm running is:

import os   import time  x in range(10):       print "testing"       time.sleep(10)   

and i'm using subprocess.popen() p.communicate(), wrapper wait 100 seconds, , print of output. i'd wrapper invisible possible - ideally in case print "testing" once every ten seconds.

if point me towards way of doing this, i'd appreciate it.

thanks!

i believe can replace sys.excepthook own function. can read in python documentation.

basically, allows customize happens when exception percolates point of forcing python interpreter quit. use this:

import sys  def my_excepthook(type, value, tb):     # can log exception file here     print 'in exception handler'      # following line default (prints err)     sys.__excepthook__(type, value, tb)  sys.excepthook = my_excepthook 

you'll want @ the traceback module, formatting traceback get.


Comments

Popular posts from this blog

python - Scipy curvefit RuntimeError:Optimal parameters not found: Number of calls to function has reached maxfev = 1000 -

c# - How to add a new treeview at the selected node? -

java - netbeans "Please wait - classpath scanning in progress..." -