tags:

views:

33

answers:

1

I was hoping that putting 'sys.exit(1)' and catching it later like this will work.

xml_open()
try:
  run(reloader=True, host='localhost', port=8080)
except SystemExit:
  xml_save()
  print "Exited ..."

Is there any other solution to exit these python micro-frameworks to exit from inside the handlers ?

+1  A: 

If its not being handled then check whether Its really executes sys.exist(1) statement, because It may happen some other exception raised which is not being handled try this....

xml_open()
try:
  run(reloader=True, host='localhost', port=8080)
except SystemExit:
  xml_save()
  print "Exited ..."
except Exception, e:
  print "ohhh no.......",str(e)
  import pdb
  pdb.post_mortem()
  sys.exit(-1)
Tumbleweed
sys.exit() raises SystemExit .. it'll not raise any other exception. See http://docs.python.org/library/sys.html#sys.exit
Vardhan Varma
I mean check whether its getting called or not !
Tumbleweed
@shahjapan oh ok .. actually problem here is with so many layers of fn calls and try-except ... some thing eats up the exception .. there seems to be some handling being done , but it's coming to my exception handler at all.
Vardhan Varma
I've updated the code and added pdb so you can trace the error, from which layer its get exhausted...
Tumbleweed