u40301

Email when python encounters an error (9.3.1)

Discussion created by u40301 on Jul 7, 2011
Latest reply on Jul 8, 2011 by tony.farndon
Hi, wondering if anyone has a more efficient way of sending an email when a python script has crashed.  I have several scripts that run on a remote machine and would like to know when they fail.
My method is very crude and doesn't work quite right.
Currently using a Try/Except  which creates a .BAT file, the .BAT file runs a SQLPLUS statement that executes an Oracle function which sends me an email.   There must be a better way.

try:
   print "doing some stuff"

except:
   f = open('c:\\Fail_Notification.BAT', 'w')
   f.write("c:\n")
   f.write("cd" + "\\\n")
   f.write('SQLPLUS DB_USER/PASSWORD@DB1 @\\\\scripts\\python\\fail_notification.sql \"Frank@Hotmail.com\" \"Script has failed.\"')
   f.close()
   os.spawnv(os.P_WAIT, 'c:\\projects\\Fail_Notification.BAT', [])
   os.remove('c:\\Fail_Notification.BAT')

Outcomes