Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!xlned.com!feeder5.xlned.com!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.005 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'subject:error': 0.03; 'insert': 0.05; 'output': 0.05; 'matches': 0.07; 'skip:u 30': 0.07; 'exception,': 0.09; 'skip:/ 10': 0.09; 'cc:addr:python- list': 0.11; 'block.': 0.16; 'blocks': 0.16; 'commented': 0.16; 'created.': 0.16; 'gauld': 0.16; 'naming': 0.16; 'skip:n 50': 0.16; 'subject:exception': 0.16; 'url:flickr': 0.16; 'variables,': 0.16; 'exception': 0.16; 'folder': 0.16; 'weird': 0.16; 'wrote:': 0.18; 'code.': 0.18; 'variable': 0.18; 'module': 0.19; 'producing': 0.19; '>>>': 0.22; 'aug': 0.22; 'bruce': 0.22; 'cc:addr:python.org': 0.22; 'print': 0.22; 'cc:2**1': 0.23; 'error': 0.23; 'exists': 0.24; 'cc:no real name:2**0': 0.24; 'subject:/': 0.26; 'gets': 0.27; 'header:In-Reply-To:1': 0.27; 'tried': 0.27; 'errors': 0.30; 'statement': 0.30; 'message- id:@mail.gmail.com': 0.30; "i'm": 0.30; 'url:mailman': 0.30; 'code': 0.31; 'getting': 0.31; 'too.': 0.31; 'usually': 0.31; 'alan': 0.31; 'block,': 0.31; 'catching': 0.31; 'indentation': 0.31; 'steven': 0.31; 'file': 0.32; 'figure': 0.32; 'skip:- 30': 0.32; 'quite': 0.32; 'url:python': 0.33; 'style': 0.33; 'could': 0.34; 'created': 0.35; 'except': 0.35; 'possible.': 0.35; 'skip:s 30': 0.35; 'etc': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'version': 0.36; 'combination': 0.36; 'consistent': 0.36; 'url:listinfo': 0.36; 'possible': 0.36; 'url:org': 0.36; 'level': 0.37; 'starting': 0.37; 'being': 0.38; 'skip:o 20': 0.38; 'files': 0.38; 'pm,': 0.38; 'does': 0.39; 'bad': 0.39; 'sure': 0.39; 'url:mail': 0.40; 'read': 0.60; 'deleting': 0.60; 'skip:n 30': 0.60; 'tell': 0.60; 'skip:o 30': 0.61; 'simple': 0.61; 'times': 0.62; 'offer': 0.62; 'information': 0.63; 'name': 0.63; 'places': 0.64; 'more': 0.64; 'life': 0.66; 'here': 0.66; 'url:me': 0.69; 'commenting': 0.84; 'confusing': 0.84; 'excessive': 0.84; 'fail.': 0.84; 'subject:try': 0.84 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=CsYcf2cVaWReH0IZz0xie7lOlZC63yCjG/zpFMWRbt0=; b=hRPbm5m2m4fkihHJhQ4a50yXO/adWpEAhLIiT9aARyY59Av4pfQ1A4n4odR7jt//tm 7SWaUsuNaJo2WdRi4st7gdG1uvcHPOEoQJFWX6fRe47DUWtSwl5XeS8kLg6MYEkCELkz vQxXrz3EVDMu3Q+6aOIYx/cqmH7677rGkKo7/6gKiZFiF4UBGdirqCxIdVuzPNKo/qTx wTmmuN0NKqX6DZXI/zxOvoifKYIulO7wtBaqexwta7vY1+6hCjSrWVRkT5cSTIA4ngjW MybpBbFAkb3MfbjiUnXLvZDKzYChIurQGP5ZPua9FnzreEwozq7+WOJP4/kY8PaKrqZa Pozw== MIME-Version: 1.0 X-Received: by 10.50.79.135 with SMTP id j7mr31179748igx.9.1407101586687; Sun, 03 Aug 2014 14:33:06 -0700 (PDT) In-Reply-To: References: Date: Sun, 3 Aug 2014 17:33:06 -0400 Subject: Re: try/exception - error block From: bruce To: Alan Gauld Content-Type: text/plain; charset=UTF-8 Cc: python-list@python.org, Python Tutor Mailing List 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: 108 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1407101594 news.xs4all.nl 2844 [2001:888:2000:d::a6]:48929 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:75620 Hi Alan. Yep, the err file in the exception block gets created. and the weird thing is it matches the time of the abrtd information in the /var/log/messages log.. Just nothing in the file! On Sun, Aug 3, 2014 at 4:01 PM, Alan Gauld wrote: > On 03/08/14 18:52, bruce wrote: > >>> but in all that.. no one could tell me .. why i'm not getting any >>> errs/exceptions in the err file which gets created on the exception!!! > > > Does the file actually get created? > Do you see the print statement output - are they what you expect? > > Did you try the things Steven suggested. > > >>> 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("-","_") > > > This is usually a bad idea. You are using name for the process and its > output. Use more names... > What about: > > uuid=subprocess.Popen('uuidgen -t',shell=True,stdout=subprocess.PIPE) > output=uuid.communicate()[0].strip() > name=output.replace("-","_") > >>> name2="/home/ihubuser/parseErrTest/pp_"+name+".dat" > > > This would be a good place to insert a print > > print name2 > >>> ofile1=open(name2,"w+") > > > Why are you using w+ mode? You are only writing. > Keep life as simple as possible. > >>> ofile1.write(e) > > > e is quite likely to be empty > >>> ofile1.write(aaa) > > > Are you sure aaa exists at this point? Remember you are catching all errors > so if an error happens prior to aaa being created this will > fail. > >>> ofile1.close() > > > You used the with form earlier, why not here too. > It's considered better style... > > Some final comments. > 1) You call sys.exit() several times inside > the try block. sys.exit will not be caught by your except block, > is that what you expect?. > > 2) The combination of confusing naming of variables, > reuse of names and poor code layout and excessive commented > code makes it very difficult to read your code. > That makes it hard to figure out what might be going on. > - Use sensible variable names not a,aaa,z, etc > - use 3 or 4 level indentation not 2 > - use a version control system (RCS,CVS, SVN,...) instead > of commenting out big blocks > - use consistent code style > eg with f as ... or open(f)/close(f) but not both > - use the os module (and friends) instead of subprocess if possible > > 3) Have you tried deleting all the files in the > /home/ihubuser/parseErrTest/ folder and starting again, > just to be sure that your current code is actually > producing the empty files? > > 4) You use tmpParseDir in a couple of places but I don't > see it being set anywhere? > > > That's about the best I can offer based on the > information available. > > -- > Alan G > Author of the Learn to Program web site > http://www.alan-g.me.uk/ > http://www.flickr.com/photos/alangauldphotos > > -- > https://mail.python.org/mailman/listinfo/python-list