8

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?

Eva Dias
  • 1,709
  • 9
  • 36
  • 67
Darek
  • 2,861
  • 4
  • 29
  • 52

1 Answers1

13

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.

halex
  • 16,253
  • 5
  • 58
  • 67