Skip to content

Preserve async shell context across cells - #1548

Open
fff122 wants to merge 1 commit into
ipython:mainfrom
fff122:fix-contextvar-across-cells-749
Open

Preserve async shell context across cells#1548
fff122 wants to merge 1 commit into
ipython:mainfrom
fff122:fix-contextvar-across-cells-749

Conversation

@fff122

@fff122 fff122 commented Aug 14, 2026

Copy link
Copy Markdown

Fixes #749

Summary

The asynchronous cell runner created a separate task for the cell coroutine. ContextVar updates made after an await therefore remained in that task and were not available to the next execute request. The SIGINT cancellation hook also tracked the separate task.

This change runs the cell coroutine in the current execute task while retaining the cancellation hook, and persists the resulting async context for subsequent requests. The regression test sets a ContextVar after an await and verifies that the value is available in the next cell.

Validation

  • ContextVar regression test passed
  • Kernel and direct-kernel related tests passed after installing the declared ipyparallel test dependency
  • Pre-commit/Ruff checks passed
  • git diff --check passed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ContextVar not preserved when cell contains await

1 participant