Repository navigation
Do not fire pre_execute/post_execute for comms dispatched concurrently during a cell - #1588
Open
Dikshant-Neupane wants to merge 2 commits into
Open
Dikshant-Neupane wants to merge 2 commits into
Dikshant-Neupane wants to merge 2 commits into
Conversation
…y during a cell During an async cell, comm messages are dispatched concurrently while the cell holds the shell lock. Firing pre_execute/post_execute for those callbacks parents any hook output to the comm_msg instead of the cell's execute_request, so frontends drop it and the hook's queue is drained before the cell's own post_execute fires (see ipython#1564). A context variable marks the concurrent dispatch, and BaseComm.handle_msg skips the two events only there; comms handled while no cell is running keep the previous behaviour.
The annotation was evaluated at import time, so environments with a comm version that has no base_comm.MessageType failed to import the module. Quoting it makes the evaluation lazy; the runtime behaviour is unchanged.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #1564
When a comm message arrives while an async cell is running, the comm is dispatched concurrently while the cell holds the shell lock, and pre_execute/post_execute fire for the comm callback mid-cell. Any output a post_execute hook publishes is then parented to the comm_msg instead of the cell's execute_request, so frontends drop it, and the hook's queue is drained before the cell's own post_execute fires.
The sync-cell case was already fixed by #1565; this covers the remaining async-cell case, with and without a subshell.
Fix: a context variable is set in the shell_main concurrent-dispatch branch only, and ipykernel's BaseComm.handle_msg override skips the two events when it is set. Comms handled while no cell is running keep the previous behaviour. The approach follows the discussion in the issue.
Repro (issue's reproducer, on main f87d0e0):
Tests: