可以使用 sys.exit() 退出 Bottle 框架吗

发布于 2024-09-17 23:17:02 字数 229 浏览 1 评论 0原文

我希望放置“sys.exit(1)”并稍后像这样捕获它会起作用。

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

有没有其他解决方案可以退出这些python微框架以从内部退出 处理程序?

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 ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

为你鎻心 2024-09-24 23:17:02

如果它没有被处理,那么检查它是否真的执行了 sys.exist(1) 语句,
因为可能会发生一些其他未处理的异常,请尝试这个......

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)

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)
り繁华旳梦境 2024-09-24 23:17:02

如果这对您来说仍然是一个问题,请在此处查看我的答案 为停止瓶子框架提供干净的解决方案。

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

情魔剑神 2024-09-24 23:17:02

根据我有限的经验,当重新加载器关闭时, sys.exit() 应该可以工作。否则,重新加载器将重新加载 sys.exit() 上的代码,并且您的应用程序将恢复。当然,我可能错误地理解为什么 sys.exit() 不起作用,但对我来说,当我关闭重新加载器时它就起作用了。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文