ipykernel 7.x does not schedule async background tasks after cell completion
Dieses Issue hat noch niemand übernommen.
Bewertung
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Anfängerfreundlichkeit
- 35/100
Rechercherichtung
Beginne damit, das minimale reproduzierbare Beispiel im Issue mit ipykernel 6.3.1 und 7.2.0 auszuführen, und vergleiche anschließend die Planung asynchroner Tasks nach dem Abschluss der Zelle. Verfolge den Kernel-Einstiegspunkt, der den Abschluss der Zelle und Hintergrund-asyncio-Tasks verarbeitet; abgeschlossen ist die Arbeit, wenn festgestellt wurde, ob das Verhalten beabsichtigt ist oder eine Regression darstellt, und das erwartete Verhalten dokumentiert oder getestet wurde.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
Description
In ipykernel 7.x, async background tasks created during a cell (e.g., via asyncio.ensure_future) do not continue running once the cell completes. The task resumes only after executing another cell. The same code behaves correctly on ipykernel 6.x.
This is not about widget rendering or Output; the symptom reproduces with a pure side effect (file write).
(Original discussion history for context: ipywidgets issue list shows jupyter-widgets/ipywidgets#4012 where this started, but this report is deliberately scoped to ipykernel behavior.)
Minimal Reproducible Example
import asyncio
import ipywidgets as W
from IPython.display import display
from IPython import get_ipython
q = asyncio.Queue()
button = W.Button(description="Click me")
current_cell_parent = get_ipython().get_parent()
def on_click(_):
q.put_nowait("click")
button.on_click(on_click)
async def consumer():
get_ipython().set_parent(current_cell_parent)
while True:
await q.get()
with open("consumer_log.txt", "a") as f:
f.write("GOT click\n")
asyncio.ensure_future(consumer())
display(button)
Observed behavior
With ipykernel==6.3.1, clicking the button immediately creates/updates consumer_log.txt.
With ipykernel==7.2.0 or ipykernel==7.1.0, clicking the button does not create/update the file. The file is only written after running another cell.
Expected Behavior
Async tasks created with asyncio.ensure_future (or similar mechanisms) should continue running after the originating cell finishes, just as they do under ipykernel 6.x.
Note on ipykernel PR #1451
Just as a note to help with context: this issue appears to be different from ipython/ipykernel#1451.
That pull request focused on how background thread output is routed to notebook cells, and the ipykernel 7.1.0 release notes describe it as a fix related to display/output behavior coming from threads.
In the situation described here, the behavior involves async background tasks (e.g., asyncio.ensure_future) not continuing to run once a cell has finished executing. The minimal example uses a simple file write to show that no widget mechanisms or thread‑based output routing are involved.
Question
Is this change in async scheduling behavior intentional in ipykernel 7.x?
If so:
- What is the recommended mechanism for running long‑lived async background tasks in notebooks?
If not:
- This appears to be a regression relative to ipykernel 6.x.
Context
- Python: 3.11.9
- JupyterLab: 4.5.6
- ipywidgets: 8.1.8
- ipykernel: 7.2.0
- Vorherrschende Sprache
- Python
- Sterne
- 734
- Forks
- 411
- Ø Merge
- 1 T. 5 Std.
- Gemergte PRs (30 T.)
- 8
Beitragsleitfaden
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus ipython/ipykernel
-
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 72/100
-
Schwierigkeit 4/5 3-5 Tage Anfängerfreundlichkeit 68/100
-
ipython/ipykernel#1550 · 1 Kommentar · 1 Reaktion · 1 zugewiesene Person ·
-
Schwierigkeit 3/5 1-2 Tage Anfängerfreundlichkeit 66/100
-
Schwierigkeit 4/5 3-5 Tage Anfängerfreundlichkeit 35/100
Alle Issues in ipython/ipykernel
Ähnliche Issues
-
documentation help wanted
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 90/100
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 90/100
simonw/sqlite-utils#872 ·
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 88/100
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 82/100
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100