Skip to content

Commit f2c2722

Browse files
committed
Show meaningful message when nest_asyncio=True is needed
1 parent 75642b2 commit f2c2722

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

nbclient/client.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,16 @@ def run_blocking(self, coro):
319319
if self.nest_asyncio:
320320
import nest_asyncio
321321
nest_asyncio.apply(loop)
322-
result = loop.run_until_complete(coro)
322+
try:
323+
result = loop.run_until_complete(coro)
324+
except RuntimeError as e:
325+
if str(e) == 'This event loop is already running':
326+
raise RuntimeError(
327+
'You are trying to run nbclient in an environment where an '
328+
'event loop is already running. Please pass `nest_asyncio=True` in '
329+
'`NotebookClient.execute` and such methods.'
330+
)
331+
raise
323332
return result
324333

325334
def reset_execution_trackers(self):

0 commit comments

Comments
 (0)