Browse code

fix keyboard interupt problem in notebook, see MR !29

Bas Nijholt authored on 27/11/2017 13:22:22
Showing 1 changed files
... ...
@@ -18,12 +18,22 @@ def _loop_asyncio(kernel):
18 18
         loop.call_later(kernel._poll_interval, kernel_handler)
19 19
 
20 20
     loop.call_soon(kernel_handler)
21
-    try:
22
-        if not loop.is_running():
21
+    # loop is already running (e.g. tornado 5), nothing left to do
22
+    if loop.is_running():
23
+        return
24
+    while True:
25
+        error = None
26
+        try:
23 27
             loop.run_forever()
24
-    finally:
28
+        except KeyboardInterrupt:
29
+            continue
30
+        except Exception as e:
31
+            error = e
25 32
         loop.run_until_complete(loop.shutdown_asyncgens())
26 33
         loop.close()
34
+        if error is not None:
35
+            raise error
36
+        break
27 37
 
28 38
 
29 39
 def notebook_extension():