Darek
Darek

Reputation: 2911

Python bottle runs initialization method twice

I've got a problem with bottle, the _initialize function is run twice. Example app:

 @route("/index")
 def index():
      return "bang"

 def _initialize():
      print("bam")

 if __name__ == "__main__":
     _initialize()
     run(reloader=True, host="localhost", port = 8990)

The output is:

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

Why is it happening and how can I do such pre init in bottle?

Upvotes: 8

Views: 2199

Answers (1)

halex
halex

Reputation: 16393

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

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

Upvotes: 14

Related Questions