Bottle web framework - How to stop?

前端 未结 11 1259
不知归路
不知归路 2020-12-14 06:55

When starting a bottle webserver without a thread or a subprocess, there\'s no problem. To exit the bottle app -> CTRL + c.

In a thread, ho

11条回答
  •  北海茫月
    2020-12-14 07:27

    Since bottle doesn't provide a mechanism, it requires a hack. This is perhaps the cleanest one if you are using the default WSGI server:

    In bottle's code the WSGI server is started with:

    srv.serve_forever()
    

    If you have started bottle in its own thread, you can stop it using:

    srv.shutdown()
    

    To access the srv variable in your code, you need to edit the bottle source code and make it global. After changing the bottle code, it would look like:

    srv = None #make srv global
    class WSGIRefServer(ServerAdapter):
        def run(self, handler): # pragma: no cover
            global srv #make srv global
            ...
    

提交回复
热议问题