get_traceback
kyosohma at gmail.com
kyosohma at gmail.com
Mon Jun 4 15:50:11 EDT 2007
On Jun 4, 12:23 pm, half.ital... at gmail.com wrote:
> Hi,
>
> Is there a function or idoim for returning an exception/traceback
> rather than just printing it to stdout? I'm running a deamon where
> stdout is going to /dev/null, and I'm not even watching it..until
> now. All the functions I found in traceback and sys seemed only to
> print the error rather than just returning it, so I resorted to this:
>
> def get_traceback():
> import traceback, tempfile
> stdout = sys.stdout
>
> f = tempfile.TemporaryFile(mode='w+')
> sys.stdout = f
>
> traceback.print_tb(sys.exc_info()[2])
> error = f.read()
> f.close()
>
> sys.stdout = stdout
> return error
>
> Whats the right function?!? Thanks.
>
> ~Sean
I use the traceback module as you do and I usually have it email the
traceback to me if there's an error. You could also have the script
redirect stdout to a file object.
Mike
More information about the Python-list
mailing list