【问题标题】:Restart Bottle app (programmatically)重启 Bottle 应用程序(以编程方式)
【发布时间】:2015-07-30 20:12:26
【问题描述】:

如何以编程方式重新启动我的 Bottle 应用?

def error_handler(error):
    if error.message == "connection already closed":
        RESTART_BOTTLE_SERVER()  # This will reacquire connection

【问题讨论】:

  • 快速浏览一下 - 可能你只需要使用线程?(也许我弄错了,抱歉跑题了)
  • 我的重启你想做什么去起始页或者刷新页面或者从头开始
  • 这取决于你使用的服务器——而不是瓶子本身。但我怀疑你可能还没有完全考虑到这一点。例如:导致错误的请求发生了什么;它仍在处理中。瓶子正在处理的所有其他请求会发生什么?
  • 您可以使用此答案stackoverflow.com/questions/11282218/…中的方法停止瓶子框架@
  • 嗯,这可能是我正在寻找的解决方案。把它写成答案?

标签: python database-connection bottle restart peewee


【解决方案1】:

您可以使用this answer 中描述的方法停止瓶子应用程序(线程)。

【讨论】:

    【解决方案2】:

    我建议您在操作系统的后台将您的 Bottle 服务器作为守护程序运行。您可以启动和停止服务器并使用简单的 python 代码来终止线程。 BottleDaemon 可能会为您完成这项工作。

    from bottledaemon import daemon_run
    from bottle import route
    
    @route("/hello")
    def hello():
      return "Hello World"
    
    if __name__ == "__main__":
      daemon_run()
    

    上述应用程序将在后台启动。这个顶级脚本可用于轻松启动/停止后台进程:

    jonathans-air:bottle-daemon jhood$ python bottledaemon/bottledaemon.py
    usage: bottledaemon.py [-h] {start,stop}
    

    现在您可以使用bottledaemon.py 来启动或停止或重新启动您的应用程序,并从您的主python 文件中调用它。

    【讨论】:

    • 是的,我倾向于使用初始化系统(systemd、upstart 或常规初始化脚本)来保持它始终运行。
    猜你喜欢
    • 2011-09-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-09-26
    • 1970-01-01
    • 2011-05-22
    • 1970-01-01
    • 2013-02-05
    相关资源
    最近更新 更多