在iPythonNotebook中中断Flask应用程序会导致ZMQerror

时间:2016-01-26 18:09:48

标签: flask ipython-notebook zeromq pyzmq

我正试图在这样的flask笔记本中运行iPython app的最简单演示。

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的幽灵进程时,我什么都没得到。我想重新启动可能最有可能解决问题,但只是想知道是否有一个不需要重启的修复程序?

1 个答案:

答案 0 :(得分:3)

设置debug = False

app.run(debug=False)