8000 Handle Ctrl+C gracefully in WebAgg example · matplotlib/matplotlib@370aac0 · GitHub
[go: up one dir, main page]

Skip to content

Commit 370aac0

Browse files
committed
Handle Ctrl+C gracefully in WebAgg example
1 parent d17fe2a commit 370aac0

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

examples/user_interfaces/embedding_webagg_sgskip.py

Lines changed: 15 additions & 1 deletion
8000 429E
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import json
1717
import mimetypes
1818
from pathlib import Path
19+
import signal
1920
import socket
2021

2122
try:
@@ -259,4 +260,17 @@ def __init__(self, figure):
259260
print(f"Listening on http://{addr}:{port}/")
260261
print("Press Ctrl+C to quit")
261262

262-
tornado.ioloop.IOLoop.instance().start()
263+
ioloop = tornado.ioloop.IOLoop.instance()
264+
265+
def shutdown():
266+
ioloop.stop()
267+
print("Server stopped")
268+
269+
old_handler = signal.signal(
270+
signal.SIGINT,
271+
lambda sig, frame: ioloop.add_callback_from_signal(shutdown))
272+
273+
try:
274+
ioloop.start()
275+
finally:
276+
signal.signal(signal.SIGINT, old_handler)

0 commit comments

Comments
 (0)
0