diff --git a/lib/matplotlib/backends/backend_webagg.py b/lib/matplotlib/backends/backend_webagg.py index 9e1e4925496f..04aa4735cd19 100644 --- a/lib/matplotlib/backends/backend_webagg.py +++ b/lib/matplotlib/backends/backend_webagg.py @@ -245,6 +245,14 @@ def random_ports(port, n): @classmethod def start(cls): + import asyncio + try: + asyncio.get_running_loop() + except RuntimeError: + pass + else: + cls.started = True + if cls.started: return @@ -286,8 +294,12 @@ def ipython_inline_display(figure): import tornado.template WebAggApplication.initialize() - if not webagg_server_thread.is_alive(): - webagg_server_thread.start() + import asyncio + try: + asyncio.get_running_loop() + except RuntimeError: + if not webagg_server_thread.is_alive(): + webagg_server_thread.start() fignum = figure.number tpl = Path(core.FigureManagerWebAgg.get_static_file_path(),