[Python] intercettare gli errori di una aplicazione

2009-01-29 Thread Alessandro Dentella
Ciao,

  credo di fare una domanda semplice, ma in questo momento non mi viene in
  mente la soluzione...

  Voglio intercettare qualunque errore generato dalla applicazione che sto
  facendo per poi inviarmi per mail la stack trace (e non chiedere al mio
  cliente di inviarmela).

  L'applicazione è in PyGtk, credevo ingenuamente che bastasse fare girare
  gtk.main() in un try/except come segue ma non serve a nulla. Che devo
  fare? Immagino sia una necessità abbastanza comune ed immagino ci siano
  soluzioni ma non ho saputo farle venire fuori da google...

  sandro
  *:-)


#!/usr/bin/python

import gtk

class Test(object):

def __init__(self):
w = gtk.Window()
b = gtk.Button("Press for an error")
w.add(b)
w.show_all()

b.connect('clicked', self.on_clicked_error)

def on_clicked_error(self, widget):
print a


t = Test()


try:
gtk.main()
except Exception, e:
print "ERROR", e


-- 
Sandro Dentella  *:-)
http://sqlkit.argolinux.orgSQLkit home page - PyGTK/python/sqlalchemy
___
Python mailing list
Python@lists.python.it
http://lists.python.it/mailman/listinfo/python


Re: [Python] intercettare gli errori di una aplicazione

2009-01-29 Thread Lawrence Oluyede
On Thu, Jan 29, 2009 at 10:45 AM, Alessandro Dentella  wrote:
>  Voglio intercettare qualunque errore generato dalla applicazione che sto
>  facendo per poi inviarmi per mail la stack trace (e non chiedere al mio
>  cliente di inviarmela).

Potresti sovrascrivere sys.excepthoook:
http://www.python.org/doc/2.5.4/lib/module-sys.html

-- 
Lawrence, http://oluyede.org - http://twitter.com/lawrenceoluyede
"It is difficult to get a man to understand
something when his salary depends on not
understanding it" - Upton Sinclair
___
Python mailing list
Python@lists.python.it
http://lists.python.it/mailman/listinfo/python


Re: [Python] intercettare gli errori di una aplicazione

2009-01-29 Thread Raffaele Salmaso
Alessandro Dentella wrote:
>   Voglio intercettare qualunque errore generato dalla applicazione che sto
>   facendo per poi inviarmi per mail la stack trace (e non chiedere al mio
>   cliente di inviarmela).
prova con

---8<---
#!/usr/bin/python

import sys
import gtk
import traceback

orig=sys.excepthook
def custom_exception(_type, _value, _traceback):
traceback.print_exception(_type, _value, _traceback,
file=open('error.log','a'))
sys.excepthook=custom_exception

class Test(object):
def __init__(self):
w = gtk.Window()
b = gtk.Button("Press for an error")
w.add(b)
w.show_all()

b.connect('clicked', self.on_clicked_error)

def on_clicked_error(self, widget):
print a

t = Test()

gtk.main()



-- 
()_() | That said, I didn't actually _test_ my patch.  | +
(o.o) | That's what users are for! | +---+
'm m' |   (Linus Torvalds) |  O  |
(___) |  raffaele at salmaso punto org |
___
Python mailing list
Python@lists.python.it
http://lists.python.it/mailman/listinfo/python


Re: [Python] intercettare gli errori di una aplicazione

2009-01-29 Thread Alessandro Dentella
On Thu, Jan 29, 2009 at 11:09:59AM +0100, Lawrence Oluyede wrote:
> On Thu, Jan 29, 2009 at 10:45 AM, Alessandro Dentella  wrote:
> >  Voglio intercettare qualunque errore generato dalla applicazione che sto
> >  facendo per poi inviarmi per mail la stack trace (e non chiedere al mio
> >  cliente di inviarmela).
> 
> Potresti sovrascrivere sys.excepthoook:
> http://www.python.org/doc/2.5.4/lib/module-sys.html


perfetto!

grazie
*:-)
___
Python mailing list
Python@lists.python.it
http://lists.python.it/mailman/listinfo/python