Skip to content

docs: clarify Page.update() must run on the event-loop thread - #7127

Open
daneeller wants to merge 1 commit into
flet-dev:mainfrom
daneeller:docs-page-update-thread-contract
Open

daneeller wants to merge 1 commit into
flet-dev:mainfrom
daneeller:docs-page-update-thread-contract

Conversation

@daneeller

@daneeller daneeller commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Follow-up to #7107. As offered in that thread, this adds a short paragraph to the Threading section of the Async apps guide.

What this clarifies

There are two distinct paths for pushing control changes to the client, and the guide currently documents neither:

  • Property changes / reactive state from a worker are scheduled on the event loop. Session.schedule_update() was made thread-safe in fix: make Session.schedule_update() and schedule_effect() thread-safe #7113 (call_soon_threadsafe()), and its source now explicitly states it is safe to call from any thread. Reactive set_state() changes are marshalled to the loop as well.
  • An explicit Control.update() call is different: it calls Session.patch_control() synchronously on the calling thread, and that path sends the patch without taking __updates_lock (the lock in session.py guards the queue and session flags only). Calling it from a worker thread can interleave patches with the loop thread.

The paragraph states the contract — call update() from the event-loop thread — and shows how a worker can marshal the call back with page.run_task().

Scope

Documentation only, 19 added lines. No framework behaviour is changed. The example passes the coroutine function to run_task() (not a called coroutine), matching the existing guidance in the Background tasks section.

I raised #7107 after tracing patch_control() on 0.86.5 and checking the equivalent path on main; the scheduler path is now fixed, but the explicit update() path remains unchanged, so the documentation gap is still open. Happy to adjust the wording if maintainers prefer a different phrasing or placement.

Summary by Sourcery

Documentation:

  • Clarify that explicit Control.update() calls must run on the event-loop thread, while worker-thread property and reactive state changes are safely scheduled, and show how to marshal updates with page.run_task().

Control property changes and reactive Component state from a worker are scheduled on the loop, but explicit update() sends its patch synchronously on the calling thread. Document the distinction and show marshalling the call back via page.run_task(). Follow-up to flet-dev#7107.

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've reviewed your changes and they look great!


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

This branch has not been deployed

No deployments
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.

1 participant