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

Interrupting Flask app in iPythonNotebook cause ZMQerror

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

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

然后我 %tbed 并得到以下回溯:

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 进程时,我一无所获。我想重新启动很可能会解决所有问题,但只是想知道是否有不需要重新启动的修复程序?

设置调试=假

app.run(debug=False)