Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Yield to give "synchronous" writes a chance to complete #1388

Merged
merged 2 commits into from
May 16, 2024
Merged

Conversation

jcheng5
Copy link
Collaborator

@jcheng5 jcheng5 commented May 15, 2024

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 button
  • After the app loads, press the button

Without this fix, only one box shows progress. With this fix, they all do.

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 commit 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.
@jcheng5 jcheng5 requested a review from wch May 15, 2024 17:28
@jcheng5 jcheng5 added this pull request to the merge queue May 16, 2024
Merged via the queue into main with commit 7d5b616 May 16, 2024
32 checks passed
@jcheng5 jcheng5 deleted the yield-for-writes branch May 16, 2024 03:59
@jcheng5 jcheng5 mentioned this pull request May 17, 2024
schloerke added a commit that referenced this pull request May 20, 2024
* main:
  bug(output transformer): fix transformer auto-registration (#1394)
  fix: Add wait till pulse animation has started (#1393)
  bug(test-deploy): Add retries for deploy tests (#1392)
  Add busy indicator tests (#1391)
  Yield to give "synchronous" writes a chance to complete (#1388)
  chore(busy indicator): Update busy indicator css files (#1389)
  feat(cli): Add `shiny --version` (#1387)
  fix(selectize): Accept jsonifiable values in `options` dictionary (#1382)
  bug(data frame): Use `<ID>_data_view_rows` (#1386)
schloerke added a commit that referenced this pull request May 20, 2024
* data_view_meta:
  Add demo apps for `update_sort()` and `update_filter()`
  Add `update_sort()` and `update_filter()` to DF
  bug(output transformer): fix transformer auto-registration (#1394)
  fix: Add wait till pulse animation has started (#1393)
  bug(test-deploy): Add retries for deploy tests (#1392)
  Add busy indicator tests (#1391)
  Yield to give "synchronous" writes a chance to complete (#1388)
  chore(busy indicator): Update busy indicator css files (#1389)
  `ColumnFilter` and `ColumnSort` should use `col: num` and not `id: str` for consistency
  Lints
  Have `.data_view()` use `.data_view_info()` information for consistent subsetting
  feat(cli): Add `shiny --version` (#1387)
  fix(selectize): Accept jsonifiable values in `options` dictionary (#1382)
  bug(data frame): Use `<ID>_data_view_rows` (#1386)
  test(data frame): Verify that data frame's outputs are reset before moving forward (#1383)
  Send busy/idle at the right times (#1380)
  feat(data frame): Restore `input.<ID>_selected_rows()`. Rename `input.<ID>_data_view_indices` to `input.<ID>_data_view_rows` (#1377)
  Apply suggestions from code review
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.

Some busy indicators not firing
2 participants