重启Bottle app(以编程方式)

时间:2015-05-19 06:25:51

标签: python database-connection bottle restart peewee

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

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

2 个答案:

答案 0 :(得分:1)

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

答案 1 :(得分:0)

I'll recommed you'll run your bottle server as a daemon in the background on your OS. You can than start and stop your server and use simple python code to kill the thread. BottleDaemon might do the job for you.

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.