1

How do I restart my Bottle app programmatically?

def error_handler(error):
    if error.message == "connection already closed":
        RESTART_BOTTLE_SERVER()  # This will reacquire connection
A T
  • 13,008
  • 21
  • 97
  • 158
  • Just after quick look - probably you just need to use threads?(Maybe I get it wrong, sorry for off topic then) – Andrii Rusanov May 19 '15 at 06:35
  • My restart what do you want to do go to the starting page or refresh the page or start again from beginning – The6thSense May 19 '15 at 06:57
  • It depends on the server you're using--not on Bottle per se. But I'm suspicious that perhaps you haven't thought this through completely. For example: what happens to the request that caused the error; it's still processing. And what happens to all the other requests bottle is handling? – ron rothman May 19 '15 at 21:19
  • You can stop the bottle framework using the approach in this answer http://stackoverflow.com/questions/11282218/bottle-web-framework-how-to-stop/16056443#16056443 – mike Nov 13 '15 at 14:42
  • Hmm, that might be the solution I was seeking. Write it up into an answer? – A T Nov 13 '15 at 14:56

2 Answers2

1

You can stop the bottle app (thread) with the approach described in this answer.

Community
  • 1
  • 1
mike
  • 1,734
  • 1
  • 23
  • 32
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.

scre_www
  • 2,536
  • 4
  • 20
  • 30
  • Yeah, I tend to use the init system (systemd, upstart or regular init scripts) to keep it always running. – A T Nov 12 '15 at 13:21