Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #75623 > unrolled thread
| Started by | Peter Otten <__peter__@web.de> |
|---|---|
| First post | 2014-08-04 00:20 +0200 |
| Last post | 2014-08-04 00:20 +0200 |
| Articles | 1 — 1 participant |
Back to article view | Back to comp.lang.python
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: try/exception - error block Peter Otten <__peter__@web.de> - 2014-08-04 00:20 +0200
| From | Peter Otten <__peter__@web.de> |
|---|---|
| Date | 2014-08-04 00:20 +0200 |
| Subject | Re: try/exception - error block |
| Message-ID | <mailman.12598.1407104469.18130.python-list@python.org> |
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()
Back to top | Article view | comp.lang.python
csiph-web