From cc8c8617a4e078afcb6ed8de0235be505561dea1 Mon Sep 17 00:00:00 2001 From: ines Date: Sat, 3 Jun 2017 13:24:56 +0200 Subject: [PATCH] Shut down displaCy server on KeyboardInterrupt --- spacy/displacy/__init__.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/spacy/displacy/__init__.py b/spacy/displacy/__init__.py index 3bb0b8aec..8468720cd 100644 --- a/spacy/displacy/__init__.py +++ b/spacy/displacy/__init__.py @@ -56,7 +56,12 @@ def serve(docs, style='dep', page=True, minify=False, options={}, manual=False, render(docs, style=style, page=page, minify=minify, options=options, manual=manual) httpd = simple_server.make_server('0.0.0.0', port, app) prints("Using the '%s' visualizer" % style, title="Serving on port %d..." % port) - httpd.serve_forever() + try: + httpd.serve_forever() + except KeyboardInterrupt: + prints("Shutting down server on port %d." % port) + finally: + httpd.server_close() def app(environ, start_response):