Closed josephernest closed 4 years ago
I solved it with a new thread:
from bottle import WSGIRefServer, run, route
from threading import Thread
@route('/')
def index():
return 'Hello world'
@route('/stop')
def stopit():
Thread(target=shutdown).start()
def shutdown():
server.srv.shutdown()
server = WSGIRefServer(port=80)
run(server=server)
For anyone else struggling to start the server again after shutting it down: you may need to call server_close
as well to free up the port and avoid error: [Errno 98] Address already in use
errors.
Extending from the example above:
def shutdown():
server.srv.shutdown()
server.srv.server_close()
Since 0.13dev now exposes the server object in
self.srv
for theWSGIRefServer
, we could use it for shutdown like this, which is essentially the same than this answer on StackOverflow:Opening http://localhost/ works, but opening http://localhost/stop does not, why?