ipykernel 7.x does not schedule async background tasks after cell completion
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 35/100
Direzione di ricerca
Inizia eseguendo l’esempio minimo riproducibile nell’issue con ipykernel 6.3.1 e 7.2.0, quindi confronta la pianificazione delle attività asincrone dopo il completamento della cella. Traccia il punto di ingresso del kernel che gestisce il completamento della cella e le attività asyncio in background; il lavoro è completato quando viene determinato se il comportamento è intenzionale o se si tratta di una regressione e il comportamento previsto viene documentato o testato.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
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
- Lingua principale
- Python
- Stelle
- 734
- Fork
- 411
- Merge medio
- 1g 2h
- PR unite (30g)
- 9
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di ipython/ipykernel
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 72/100
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 48/100
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 68/100
-
ipython/ipykernel#1550 · 1 commento · 1 reazione · 1 assegnatario ·
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 66/100
Tutte le issue di ipython/ipykernel
Issue simili
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 90/100
learningequality/ricecooker#747 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
BSData/horus-heresy-3rd-edition#3171 ·
-
enhancement
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
run-llama/llama_index#23199 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 84/100
KhronosGroup/glTF-Blender-IO#2769 ·