Redirecting STDOUT to a Python Variable
ross.marsden at gmail.com
ross.marsden at gmail.com
Sat Sep 22 17:57:52 EDT 2012
To capture the traceback, so to put it in a log, I use this
import traceback
def get_traceback(): # obtain and return the traceback
exc_type, exc_value, exc_traceback = sys.exc_info()
return ''.join(traceback.format_exception(exc_type, exc_value, exc_traceback))
Suppose I have a script run by the scheduler, this captures the traceback form any problems and emails them.
if __name__ == '__main__':
try:
Runs_unattended()
except:
send_mail(send_from = yourEmailAddress,
send_to = [ yourEmailAddress ], subject = 'Runs_unattended',
text = '%s' % get_traceback(),
files = [], server=yourLocalSMTP)
More information about the Python-list
mailing list