简体   繁体   English

重新启动Bottle应用程序(以编程方式)

[英]Restart Bottle app (programmatically)

How do I restart my Bottle app programmatically? 如何以编程方式重启我的Bottle应用程序?

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

您可以使用此答案中描述的方法停止bottle应用程序(线程)。

I'll recommed you'll run your bottle server as a daemon in the background on your OS. 我建议您将您的Bottle Server作为后台程序在后台运行。 You can than start and stop your server and use simple python code to kill the thread. 然后,您可以启动和停止服务器,并使用简单的python代码杀死线程。 BottleDaemon might do the job for you. BottleDaemon可能会为您完成这项工作。

from bottledaemon import daemon_run
from bottle import route

@route("/hello")
def hello():
  return "Hello World"

if __name__ == "__main__":
  daemon_run()

The above application will launch in the background. 上面的应用程序将在后台启动。 This top-level script can be used to start/stop the background process easily: 此顶级脚本可用于轻松启动/停止后台进程:

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

Now you can use bottledaemon.py to start or stop or restart your application and call it from your main python file. 现在,您可以使用bottledaemon.py来启动或停止或重新启动应用程序,并从主python文件中调用它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM