Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 963
Darek Avatar asked Oct 25 '12 08:10

Darek


1 Answers

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.

like image 83
halex Avatar answered Nov 16 '22 02:11

halex