Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #24864

Re: adding a simulation mode

References <mailman.1786.1341394979.4697.python-list@python.org> <4ff44823$0$29988$c3e8da3$5496439d@news.astraweb.com> <CAF_E5JbDfND7g0fjqBdxJsVXwLAZLFmiXYd+GpD2_OTPWTXobQ@mail.gmail.com>
Date 2012-07-04 15:19 +0100
Subject Re: adding a simulation mode
From andrea crotti <andrea.crotti.0@gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.1792.1341411557.4697.python-list@python.org> (permalink)

Show all headers | View raw


> Yes there is no easy solution apparently..  But I'm also playing
> around with vagrant and virtual machine generations, suppose I'm able
> to really control what will be on the machine at time X, creating it
> on demand with what I need, it might be a good way to solve my
> problems (a bit overkill and slow maybe though).
>
> I'll try the sys.excepthook trick first, any error should give me an
> exception, so if I catch them all I think it might work already..


I actually thought that the sys.excepthook would be easy but it's not
so trivial apparently:
This simple sample never reaches the print("here"), because even if
the exception is catched it still quits with return code=1.

I also tried to catch the signal but same result, how do I make it
continue and just don't complain?

The other option if of course to do a big try/except, but I would
prefer the excepthook solution..


import sys
from shutil import copy

def my_except_hook(etype, value, tb):
    print("got an exception of type", etype)


if __name__ == '__main__':
    sys.excepthook = my_except_hook
    copy('sdflsdk')
    print("here")

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

adding a simulation mode andrea crotti <andrea.crotti.0@gmail.com> - 2012-07-04 10:42 +0100
  Re: adding a simulation mode Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-07-04 13:41 +0000
    Re: adding a simulation mode andrea crotti <andrea.crotti.0@gmail.com> - 2012-07-04 14:59 +0100
    Re: adding a simulation mode andrea crotti <andrea.crotti.0@gmail.com> - 2012-07-04 15:19 +0100
  Re: adding a simulation mode Paul Rubin <no.email@nospam.invalid> - 2012-07-04 10:01 -0700

csiph-web