gpt4 book ai didi

flask - 中断 iPythonNotebook 中的 Flask 应用程序导致 ZMQerror

转载 作者:行者123 更新时间:2023-12-02 07:33:36 25 4
gpt4 key购买 nike

我正在尝试在这样的 flask 笔记本中运行 iPython 应用程序的最简单演示。

from flask import Flask
app = Flask(__name__)

@app.route('/')
def hello_world():.
return 'Hello World!'

if __name__ == '__main__':
app.run(d)

我第一次运行它,一切都很好。然后我用 app.run() 中断了单元格。但下次我运行它时,笔记本会返回一些错误消息,如下所示:

An exception has occurred, use %tb to see the full traceback.

SystemExit: 1

然后我对 %tb 进行了编辑并得到以下回溯:

SystemExit                                Traceback (most recent call last)
<ipython-input-7-a59dfe133898> in <module>()
----> 1 myapp.run(debug=True)

C:\Users\Lewis\AppData\Local\Enthought\Canopy\User\lib\site-packages\flask\app.pyc in run(self, host, port, debug, **options)
770 options.setdefault('use_debugger', self.debug)
771 try:
--> 772 run_simple(host, port, self, **options)
773 finally:
774 # reset the first request information if the development server

C:\Users\Lewis\AppData\Local\Enthought\Canopy\User\lib\site-packages\werkzeug\serving.pyc in run_simple(hostname, port, application, use_reloader, use_debugger, use_evalex, extra_files, reloader_interval, reloader_type, threaded, processes, request_handler, static_files, passthrough_errors, ssl_context)
688 from ._reloader import run_with_reloader
689 run_with_reloader(inner, extra_files, reloader_interval,
--> 690 reloader_type)
691 else:
692 inner()

C:\Users\Lewis\AppData\Local\Enthought\Canopy\User\lib\site-packages\werkzeug\_reloader.pyc in run_with_reloader(main_func, extra_files, interval, reloader_type)
248 reloader.run()
249 else:
--> 250 sys.exit(reloader.restart_with_reloader())
251 except KeyboardInterrupt:
252 pass

SystemExit: 1

没有告诉我太多,所以我查看了启动 iPython 的 cmd 并看到了以下内容:回溯(最近一次调用最后一次):

  File "C:\Users\Lewis\AppData\Local\Enthought\Canopy\User\lib\site-packages\ipy
kernel\__main__.py", line 3, in <module>
app.launch_new_instance()
File "C:\Users\Lewis\AppData\Local\Enthought\Canopy\User\lib\site-packages\traitlets\config\application.py", line 588, in launch_instanceapp.initialize(argv)
File "<decorator-gen-122>", line 2, in initialize
File "C:\Users\Lewis\AppData\Local\Enthought\Canopy\User\lib\site-packages\tra
itlets\config\application.py", line 74, in catch_config_error
return method(app, *args, **kwargs)
File "C:\Users\Lewis\AppData\Local\Enthought\Canopy\User\lib\site-packages\ipy
kernel\kernelapp.py", line 375, in initialize
self.init_sockets()
File "C:\Users\Lewis\AppData\Local\Enthought\Canopy\User\lib\site-packages\ipy
kernel\kernelapp.py", line 231, in init_sockets
self.shell_port = self._bind_socket(self.shell_socket, self.shell_port)
File "C:\Users\Lewis\AppData\Local\Enthought\Canopy\User\lib\site-packages\ipy
kernel\kernelapp.py", line 173, in _bind_socket
s.bind("tcp://%s:%i" % (self.ip, port))
File "zmq/backend/cython/socket.pyx", line 489, in zmq.backend.cython.socket.S
ocket.bind (zmq\backend\cython\socket.c:4824)
File "zmq/backend/cython/checkrc.pxd", line 25, in zmq.backend.cython.checkrc.
_check_rc (zmq\backend\cython\socket.c:7055)
raise ZMQError(errno)
ZMQError: Address in use

看来 iPython 笔记本服务器没有正确处理我的中断。但是当我尝试寻找监听端口 5000 的 Ghost 进程时,我什么也没得到。我想重新启动很可能可以解决所有问题,但只是想知道是否有不需要重新启动的修复?

最佳答案

设置debug=False

app.run(debug=False)

关于flask - 中断 iPythonNotebook 中的 Flask 应用程序导致 ZMQerror,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35020838/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com