Python bottle runs initialization method twice

I have a bottle problem, the _initialize function runs twice. Application example:

  @route("/index") def index(): return "bang" def _initialize(): print("bam") if __name__ == "__main__": _initialize() run(reloader=True, host="localhost", port = 8990) 

Output:

 bam bam Bottle v0.11.rc1 server starting up (using WSGIRefServer())... Listening on http://localhost:8080/ Hit Ctrl-C to quit. 

Why is this happening and how can I make such a pre init in a bottle?

+7
source share
1 answer

The problem is the reloader=True argument to the run function. See http://bottlepy.org/docs/dev/tutorial.html#auto-reloading for a suggestion:

All module level code is executed at least twice! Be careful.

+11
source

All Articles