Yield to give "synchronous" writes a chance to complete #1388
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.
Fixes #1381
During a synchronous phase of the event loop, we can build up network messages that need to get to the client. Because writes are naturally async, we do some weird stuff to semi-execute them which usually but doesn't always succeed. In the case where the write doesn't succeed, they're held at least until the next time the current task yields; before this commit, that could be a long time indeed, if the app is written synchronously (as about 100% of Shiny apps are).
This change yields to the event loop after invalidating the session, which gives the writes a chance to complete. This should take care of the observed problem of progress messages not making it (issue #1381). It also yields after each successful
@effect
, in case insert_ui, custom messages, etc. were sent during the@effect
, and also so outputs' automatic progress messages can propagate to the client.Repro steps
Reproduced on Windows, Python 3.11 and 3.12. (Did NOT reproduce on macOS.)
shiny run examples\busy_indicators\app.py
-- do NOT use the--reload
flag nor the VS Code play buttonWithout this fix, only one box shows progress. With this fix, they all do.