Bottle 有问题,_initialize
函数运行了两次。示例应用:
@route("/index")
def index():
return "bang"
def _initialize():
print("bam")
if __name__ == "__main__":
_initialize()
run(reloader=True, host="localhost", port = 8990)
输出是:
bam
bam
Bottle v0.11.rc1 server starting up (using WSGIRefServer())...
Listening on http://localhost:8080/
Hit Ctrl-C to quit.
为什么会发生这种情况,我该如何在瓶中进行这种预初始化?
最佳答案
问题是 run
函数的 reloader=True
参数。参见 http://bottlepy.org/docs/dev/tutorial.html#auto-reloading对于句子:
All module-level code is executed at least twice! Be careful.
关于Python bottle 两次运行初始化方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13064490/