Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed3a.news.xs4all.nl!xs4all!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; 'output': 0.05; 'indicated': 0.07; 'exception,': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'skip:/ 10': 0.09; 'strings.': 0.09; 'try:': 0.09; 'sfxlen:2': 0.11; '"\\n")': 0.16; 'block.': 0.16; 'func': 0.16; 'received:80.91.229.3': 0.16; 'received:dip0.t-ipconnect.de': 0.16; 'received:plane.gmane.org': 0.16; 'received:t-ipconnect.de': 0.16; 'skip:n 50': 0.16; 'subject:exception': 0.16; 'exception': 0.16; 'wrote:': 0.18; 'app': 0.19; 'file,': 0.19; 'work,': 0.20; 'appears': 0.22; 'bruce': 0.22; 'separate': 0.22; 'cc:addr:python.org': 0.22; 'print': 0.22; 'header:User-Agent:1': 0.23; 'cc:2**0': 0.24; 'cc:no real name:2**0': 0.24; 'subject:/': 0.26; 'header:X -Complaints-To:1': 0.27; 'quickly': 0.29; 'errors': 0.30; "i'm": 0.30; 'code': 0.31; 'getting': 0.31; 'posting': 0.31; 'app.': 0.31; 'exceptions': 0.31; 'file': 0.32; 'running': 0.33; "can't": 0.35; 'except': 0.35; 'skip:s 30': 0.35; 'test': 0.35; "didn't": 0.36; 'possible': 0.36; 'so,': 0.37; 'skip:o 20': 0.38; 'process,': 0.38; 'to:addr:python-list': 0.38; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'skip:n 30': 0.60; 'entire': 0.61; 'decided': 0.64; 'subject:try': 0.84; 'capture': 0.91 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Peter Otten <__peter__@web.de> Subject: Re: try/exception - error block Followup-To: gmane.comp.python.general Date: Mon, 04 Aug 2014 00:20:52 +0200 Organization: None References: Mime-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 7Bit X-Gmane-NNTP-Posting-Host: p57bd83d8.dip0.t-ipconnect.de User-Agent: KNode/4.11.5 Cc: tutor@python.org 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: 47 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1407104469 news.xs4all.nl 2830 [2001:888:2000:d::a6]:59658 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:75623 bruce wrote: > 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. > try: [...] > 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) You can't write exceptions to the file, just strings. Try print >> ofile1, e or ofile1.write(str(e) + "\n") instead of the above line. > ofile1.write(aaa) > ofile1.close() > > sys.exit()