Skip to content

Commit 12402f4

Browse files
authored
Merge pull request matplotlib#24120 from zhizheng1/fix-ipykernel
don't try to start a new event loop in WebAgg when in an ipykernel
2 parents 2828912 + 2eae445 commit 12402f4

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

lib/matplotlib/backends/backend_webagg.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,14 @@ def random_ports(port, n):
265265

266266
@classmethod
267267
def start(cls):
268+
import asyncio
269+
try:
270+
asyncio.get_running_loop()
271+
except RuntimeError:
272+
pass
273+
else:
274+
cls.started = True
275+
268276
if cls.started:
269277
return
270278

@@ -306,8 +314,12 @@ def ipython_inline_display(figure):
306314
import tornado.template
307315

308316
WebAggApplication.initialize()
309-
if not webagg_server_thread.is_alive():
310-
webagg_server_thread.start()
317+
import asyncio
318+
try:
319+
asyncio.get_running_loop()
320+
except RuntimeError:
321+
if not webagg_server_thread.is_alive():
322+
webagg_server_thread.start()
311323

312324
fignum = figure.number
313325
tpl = Path(core.FigureManagerWebAgg.get_static_file_path(),

0 commit comments

Comments
 (0)