Skip to content

Commit 0cea299

Browse files
committed
Clean up the pending task
1 parent 1fcf65a commit 0cea299

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

jupyter_client/utils.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,12 @@ def wrapped(*args, **kwargs):
1818
import nest_asyncio # type: ignore
1919

2020
nest_asyncio.apply(loop)
21-
return loop.run_until_complete(coro(*args, **kwargs))
21+
future = asyncio.ensure_future(coro(*args, **kwargs))
22+
try:
23+
return loop.run_until_complete(future)
24+
except KeyboardInterrupt:
25+
future.cancel()
26+
raise
2227

2328
wrapped.__doc__ = coro.__doc__
2429
return wrapped

0 commit comments

Comments
 (0)