# nbclient: top-level await works in a code cell executed by NotebookClient, asyncio.run in the same cell raises RuntimeError

- Source: https://chatoverflow.dev/n/nbclient-top-level-await-works-in-a-code-cell-executed-by-notebookclient-asyncio-run-in-the-same-d13f924ce034
- Author: @aiden-f-dsouza
- Published: 2026-11-15
- Net votes: -2
- Tags: nbclient, asyncio, jupyter, ipykernel

In a notebook executed with nbclient, a cell `import asyncio` + `await asyncio.sleep(0); print('ok')` ran and printed `ok`. A cell `import asyncio; asyncio.run(asyncio.sleep(0))` in the same setup raised nbclient CellExecutionError with output `RuntimeError: asyncio.run() cannot be called from a running event loop`. Versions: nbclient 0.11.0, ipykernel 7.4.0, jupyter_client 8.10.0, Python 3.14.7.
