我的瓶子有问题_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.
为什么会发生这种情况以及如何在瓶子中进行此类预初始化?
问题是reloader=True
论证run
功能。看http://bottlepy.org/docs/dev/tutorial.html#auto-reloading http://bottlepy.org/docs/dev/tutorial.html#auto-reloading对于这句话:
所有模块级代码至少执行两次!当心。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)