Flask本地服务器表现出奇怪而奇幻的行为

时间:2017-12-23 20:14:48

标签: python flask localhost

我正在开发Flask的个人网站,我注意到本地服务器为我工作的方式有些奇怪。

当我执行以下操作时:

$ export FLASK_APP=run.py
$ flask run

显示以下消息:

 * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
 * Restarting with stat
 * Debugger is active!
 * Debugger pin code: 262-302-085

这一切都很好。但是当我真正去127.0.0.1:5000时,服务器挂起,什么都没发生。当我说“挂起”时,我的意思是页面保持空白,但加载图标表示连接成功,但网站内容未加载。但是,当我CTRL+C关闭脚本时,网站会加载。在此之前,它说:

^C * Serving Flask app "run"
Traceback (most recent call last):
  File "/usr/local/bin/flask", line 11, in <module>
    sys.exit(main())
  File "/usr/local/lib/python2.7/dist-packages/flask/cli.py", line 507, in main
    cli.main(args=args, prog_name=name)
  File "/usr/local/lib/python2.7/dist-packages/flask/cli.py", line 374, in main
    return AppGroup.main(self, *args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/click/core.py", line 697, in main
    rv = self.invoke(ctx)
  File "/usr/local/lib/python2.7/dist-packages/click/core.py", line 1066, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/usr/local/lib/python2.7/dist-packages/click/core.py", line 895, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/local/lib/python2.7/dist-packages/click/core.py", line 535, in invoke
    return callback(*args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/click/decorators.py", line 64, in new_func
    return ctx.invoke(f, obj, *args[1:], **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/click/core.py", line 535, in invoke
    return callback(*args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/flask/cli.py", line 432, in run_command
    use_debugger=debugger, threaded=with_threads)
  File "/usr/local/lib/python2.7/dist-packages/werkzeug/serving.py", line 708, in run_simple
    inner()
  File "/usr/local/lib/python2.7/dist-packages/werkzeug/serving.py", line 670, in inner
    fd=fd)
  File "/usr/local/lib/python2.7/dist-packages/werkzeug/serving.py", line 564, in make_server
    passthrough_errors, ssl_context, fd=fd)
  File "/usr/local/lib/python2.7/dist-packages/werkzeug/serving.py", line 474, in __init__
    socket.SOCK_STREAM)
socket.error: [Errno 9] Bad file descriptor

我认为这是一个错误或其他什么,所以我CTRL+C然后我回到我的命令行。我刷新页面,期待网站关闭,它仍然存在!不仅如此,终端似乎已经复活了这个过程,并且当我在网站上移动并刷新页面时,终端显示HTTP 2xx状态代码。奇怪。所以我杀了铬和我的终端和网站STILL加载!所以我在最后一小时删除了我的缓存,重新启动了我的笔记本电脑,而且它还在继续!再过十分钟它就悄然失败了,但我真的不明白这里发生了什么。

任何人都可以向这个迷茫的小伙子展示一些怜悯吗因为在网站加载之前我似乎不应该 来杀死脚本。除了显而易见的东西之外,还有一些感觉。谁知道我做错了什么?我已经能够重现这个问题,现在已经不止一次了。

谢谢。

编辑:修正了一个句子并澄清了问题是可重现的。

0 个答案:

没有答案