Skip to content

Commit ea26d3e

Browse files
committed
WebAgg: reuse already running Tornado ioloop
If a Tornado ioloop is already running before WebAggApplication.start() is called, it should be re-used instead of trying to start it again. This allows one to use WebAgg in his/her external Tornado application.
1 parent d1fb195 commit ea26d3e

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

lib/matplotlib/backends/backend_webagg.py

+8-5
Original file line numberDiff line numberDiff line change
@@ -369,11 +369,14 @@ def start(cls):
369369
if cls.started:
370370
return
371371

372-
print("Press Ctrl+C to stop server")
373-
try:
374-
tornado.ioloop.IOLoop.instance().start()
375-
except KeyboardInterrupt:
376-
print("Server stopped")
372+
if not tornado.ioloop.IOLoop.instance().running():
373+
print("Press Ctrl+C to stop server")
374+
try:
375+
tornado.ioloop.IOLoop.instance().start()
376+
except KeyboardInterrupt:
377+
print("Server stopped")
378+
else:
379+
print("Server is running in an existing Tornado IOLoop")
377380

378381
cls.started = True
379382

0 commit comments

Comments
 (0)