Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'subject:error': 0.03; 'resulting': 0.04; 'elif': 0.05; 'output': 0.05; '-if': 0.07; 'indicated': 0.07; 'skip:u 30': 0.07; '"__main__":': 0.09; '#print': 0.09; '__name__': 0.09; 'exception,': 0.09; 'logic': 0.09; 'skip:# 30': 0.09; 'skip:$ 20': 0.09; 'skip:$ 30': 0.09; 'skip:/ 10': 0.09; 'try:': 0.09; 'sfxlen:2': 0.11; '"error': 0.16; '-check': 0.16; '-create': 0.16; 'block.': 0.16; 'func': 0.16; 'operates': 0.16; 'res': 0.16; 'skip:n 50': 0.16; 'skip:z 40': 0.16; 'subject:exception': 0.16; 'exception': 0.16; 'skip:# 20': 0.16; 'skip:= 10': 0.16; 'app': 0.19; 'work,': 0.20; 'thanks.': 0.20; 'appears': 0.22; 'input': 0.22; 'separate': 0.22; 'print': 0.22; 'error': 0.23; 'parse': 0.24; 'subject:/': 0.26; 'url:edu': 0.26; 'gets': 0.27; 'to:2**1': 0.27; 'idea': 0.28; 'quickly': 0.29; 'errors': 0.30; 'returned': 0.30; 'message- id:@mail.gmail.com': 0.30; 'skip:( 20': 0.30; "i'm": 0.30; 'code': 0.31; 'getting': 0.31; 'posting': 0.31; 'app.': 0.31; 'struct': 0.31; 'file': 0.32; 'checked': 0.32; 'skip:c 30': 0.32; "we're": 0.32; 'run': 0.32; 'to:addr:tutor': 0.33; 'running': 0.33; 'skip:# 10': 0.33; 'except': 0.35; 'skip:s 30': 0.35; 'skip:u 20': 0.35; 'test': 0.35; 'received:google.com': 0.35; 'var': 0.36; "didn't": 0.36; 'possible': 0.36; 'so,': 0.37; 'level': 0.37; 'skip:o 20': 0.38; 'process,': 0.38; 'to:addr:python-list': 0.38; 'skip:- 10': 0.38; 'to:addr:python.org': 0.39; 'skip:p 20': 0.39; 'skip:n 30': 0.60; 'skip:t 30': 0.61; 'entire': 0.61; 'decided': 0.64; 'determine': 0.67; 'skip:r 40': 0.68; 'skip:r 30': 0.69; 'college,': 0.84; 'skip:/ 30': 0.84; 'subject:try': 0.84; 'valid,': 0.84; 'capture': 0.91 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:date:message-id:subject:from:to:content-type; bh=IFPR2brWjPs+HAr1MmE1GnKMWDGeKTHgntJxpWYjFLU=; b=fXbFfeBdbzWdgCyb7zRdJI8PwKgTVQoh7kYIfLrTKQ8qPdQ8ebS4DCmSrD7ajI3JFK iF9nywDjjr6kUPyvvbE8K5z7ME3TKUH274WEs3JUoetenyzwPxLr7rYTUQfE3OMOYK1T dunfDqcfWfyio1bDTOop8+e768Dzgz30F0HqEmkqoHSG2C6SVxiQflPCUkIZ+EuaRFIP 7JmiYaDKSri0l0U0XUtvrQ8onv0o4/O/Pj+BWHKmcULvlDM61xWkWUQGMtjt0y3uyY4m l+m07/SccA1tUjUDpSeE8VJcN4r0jw7jHpMM9rJ5IvlTD8RgTXiE48JgTqMIYjq4Eji9 7ARA== MIME-Version: 1.0 X-Received: by 10.42.16.2 with SMTP id n2mr3789372ica.93.1407076163463; Sun, 03 Aug 2014 07:29:23 -0700 (PDT) Date: Sun, 3 Aug 2014 10:29:23 -0400 Subject: try/exception - error block From: bruce To: Python Tutor Mailing List , python-list@python.org Content-Type: text/plain; charset=UTF-8 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 245 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1407076172 news.xs4all.nl 2948 [2001:888:2000:d::a6]:43252 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:75600 Hi. I have a long running process, it generates calls to a separate py app. The py app appears to generate errors, as indicated in the /var/log/messages file for the abrtd daemon.. The errors are intermittent. So, to quickly capture all possible exceptions/errors, I decided to wrap the entire "main" block of the test py func in a try/exception block. This didn't work, as I'm not getting any output in the err file generated in the exception block. I'm posting the test code I'm using. Pointers/comments would be helpful/useful. //////////////////// the if that gets run is the fac1 logic which operates on the input packet/data.. elif (level=='collegeFaculty1'): #getClasses(url, college, termVal,termName,deptName,deptAbbrv) ret=getParseCollegeFacultyList1(url,content) //////////////////// Thanks. if __name__ == "__main__": # main app try: #college="asu" #url="https://webapp4.asu.edu/catalog" #termurl="https://webapp4.asu.edu/catalog/TooltipTerms.ext" #termVal=2141 # # get the input struct, parse it, determine the level # #cmd='cat /apps/parseapp2/asuclass1.dat' #print "cmd= "+cmd #proc=subprocess.Popen(cmd, shell=True,stdout=subprocess.PIPE) #content=proc.communicate()[0].strip() #print content #sys.exit() #s=getClasses(content) #print "arg1 =",sys.argv[0] if(len(sys.argv)<2): print "error\n" sys.exit() a=sys.argv[1] aaa=a # # data is coming from the parentApp.php # data has been rawurlencode(json_encode(t)) # -reverse/split the data.. # -do the fetch, # -save the fetched page/content if any # -create the returned struct # -echo/print/return the struct to the # calling parent/call # ##print urllib.unquote_plus(a).decode('utf8') #print "\n" #print simplejson.loads(urllib.unquote_plus(a)) z=simplejson.loads(urllib.unquote_plus(a)) ##z=simplejson.loads(urllib.unquote(a).decode('utf8')) #z=simplejson.loads(urllib2.unquote(a).decode('utf8')) #print "aa \n" print z #print "\n bb \n" # #-passed in # url=str(z['currentURL']) level=str(z['level']) cname=str(z['parseContentFileName']) # # need to check the contentFname # -should have been checked in the parentApp # -check it anyway, return err if required # -if valid, get/import the content into # the "content" var for the function/parsing # ##cmd='echo ${yolo_clientFetchOutputDir}/' cmd='echo ${yolo_clientParseInputDir}/' #print "cmd= "+cmd proc=subprocess.Popen(cmd, shell=True,stdout=subprocess.PIPE) cpath=proc.communicate()[0].strip() cname=cpath+cname #print "cn = "+cname+"\n" #sys.exit() cmd='test -e '+cname+' && echo 1' #print "cmd= "+cmd proc=subprocess.Popen(cmd, shell=True,stdout=subprocess.PIPE) c1=proc.communicate()[0].strip() if(not c1): #got an error - process it, return print "error in parse" # # we're here, no err.. got content # #fff= "sdsu2.dat" with open(cname,"r") as myfile: content=myfile.read() myfile.close() #-passed in #college="louisville" #url="http://htmlaccess.louisville.edu/classSchedule/" #termVal="4138" #print "term = "+str(termVal)+"\n" #print "url = "+url+"\n" #jtest() #sys.exit() #getTerm(url,college,termVal) ret={} # null it out to start if (level=='rState'): #ret=getTerm(content,termVal) ret=getParseStates(content) elif (level=='stateCollegeList'): #getDepts(url,college, termValue,termName) ret=getParseStateCollegeList(url,content) elif (level=='collegeFaculty1'): #getClasses(url, college, termVal,termName,deptName,deptAbbrv) ret=getParseCollegeFacultyList1(url,content) elif (level=='collegeFaculty2'): #getClasses(url, college, termVal,termName,deptName,deptAbbrv) ret=getParseCollegeFacultyList2(content) # # the idea of this section.. we have the resulting # fetched content/page... # a={} status=False if(ret['status']==True): s=ascii_strip(ret['data']) if(((s.find("-1) or (s.find("-1)) and ((s.find("-1) or (s.find("-1)) and level=='classSectionDay'): status=True #print "herh" #sys.exit() # # build the returned struct # # a['Status']=True a['recCount']=ret['count'] a['data']=ret['data'] a['nextLevel']='' a['timestamp']='' a['macAddress']='' elif(ret['status']==False): a['Status']=False a['recCount']=0 a['data']='' a['nextLevel']='' a['timestamp']='' a['macAddress']='' res=urllib.quote(simplejson.dumps(a)) ##print res name=subprocess.Popen('uuidgen -t', shell=True,stdout=subprocess.PIPE) name=name.communicate()[0].strip() name=name.replace("-","_") ## if status==True: name2=tmpParseDir+"/rr_"+name+".dat" ofile1=open(name2,"w+") ofile1.write(res) ofile1.close() print name2 if status==False: sname=tmpParseDir+"/serr_"+name+".dat" ofile1=open(sname,"w+") ofile1.write(aaa) ofile1.close() sys.exit() print "term = "+str(termVal)+"\n" print "url = "+url+"\n" getTerm(url,college,termVal) print "exit" sys.exit() except Exception, e: print e print "pycolFac1 - error!! \n"; name=subprocess.Popen('uuidgen -t', shell=True,stdout=subprocess.PIPE) name=name.communicate()[0].strip() name=name.replace("-","_") name2="/home/ihubuser/parseErrTest/pp_"+name+".dat" ofile1=open(name2,"w+") ofile1.write(e) ofile1.write(aaa) ofile1.close() sys.exit()