8000 WebAgg: raise WebAggApplication.started flag before blocking · matplotlib/matplotlib@91362e1 · GitHub
[go: up one dir, main page]

Skip to content

Commit 91362e1

Browse files
committed
WebAgg: raise WebAggApplication.started flag before blocking
Since Tornado's IOLoop start() blocks until the loop is closed, cls.started used to be set to True *after* an application actually stops working. Revert running() check since it no longer exists in newer versions of Tornado and will never return back.
1 parent 9fea430 commit 91362e1

File tree

1 file changed

+16
-9
lines changed

1 file changed

+16
-9
lines changed

lib/matplotlib/backends/backend_webagg.py

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -369,17 +369,24 @@ def start(cls):
369369
if cls.started:
370370
return
371371

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")
380-
372+
# Set the flag to True *before* blocking on IOLoop.instance().start()
381373
cls.started = True
382374

375+
"""
376+
IOLoop.running() was removed as of Tornado 2.4; see for example
377+
https://groups.google.com/forum/#!topic/python-tornado/QLMzkpQBGOY
378+
Thus there is no correct way to check if the loop has already been
379+
launched. We may end up with two concurrently running loops in that
380+
unlucky case with all the expected consequences.
381+
"""
382+
print("Press Ctrl+C to stop server")
383+
try:
384+
tornado.ioloop.IOLoop.instance().start()
385+
except KeyboardInterrupt:
386+
print("Server stopped")
387+
finally:
388+
cls.started = False
389+
383390

384391
def ipython_inline_display(figure):
385392
import tornado.template

0 commit comments

Comments
 (0)
0