Dar*_*rek 8 python web-applications bottle
我有瓶子问题,_initialize功能运行两次.应用示例:
@route("/index")
def index():
return "bang"
def _initialize():
print("bam")
if __name__ == "__main__":
_initialize()
run(reloader=True, host="localhost", port = 8990)
Run Code Online (Sandbox Code Playgroud)
输出是:
bam
bam
Bottle v0.11.rc1 server starting up (using WSGIRefServer())...
Listening on http://localhost:8080/
Hit Ctrl-C to quit.
Run Code Online (Sandbox Code Playgroud)
为什么会这样?我怎么能在瓶子里做这样的pre init?
hal*_*lex 12
问题是函数的reloader=True论证run.请参阅http://bottlepy.org/docs/dev/tutorial.html#auto-reloading中的句子:
所有模块级代码至少执行两次!小心.