user414441
user414441

Reputation:

can sys.exit() be made to exit bottle framework

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 ?

Upvotes: 5

Views: 1171

Answers (3)

mike
mike

Reputation: 1764

In case this is still an issue for you, check my answer here for a clean solution of stopping the bottle framework.

Upvotes: 1

user234932
user234932

Reputation:

From my limited experience, sys.exit() should work when reloader is turned off. Otherwise, reloader will reload the code on sys.exit() and your application will be resumed. Of course, I might be wrong about why sys.exit() doesn't work, but for me it worked when I turned off the reloader.

Upvotes: 0

shahjapan
shahjapan

Reputation: 14355

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)

Upvotes: 1

Related Questions