-
Notifications
You must be signed in to change notification settings - Fork 1.2k
feat(framework): Add context lock #7975
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,7 +15,10 @@ | |
| """Context.""" | ||
|
|
||
|
|
||
| from collections.abc import Iterator | ||
| from contextlib import contextmanager | ||
| from dataclasses import dataclass | ||
| from threading import RLock | ||
|
|
||
| from flwr.app.user_config import UserConfig | ||
|
|
||
|
|
@@ -72,3 +75,10 @@ def __init__( # pylint: disable=too-many-arguments, too-many-positional-argumen | |
| self.state = state | ||
| self.run_config = run_config | ||
| self.series_id = series_id | ||
| self._lock = RLock() | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
When a simulation or VCE Ray backend submits a AGENTS.md reference: framework/AGENTS.md:L113-L115 Useful? React with 👍 / 👎. |
||
|
|
||
| @contextmanager | ||
| def locked(self) -> Iterator[None]: | ||
| """Lock this context for an atomic in-process operation.""" | ||
| with self._lock: | ||
| yield | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Every
Contextnow has_lockinvars(context), butLegacyContext.__init__still callssuper().__init__(**vars(context)); consequently, constructing the publicLegacyContextused by the repository's ServerApp examples and e2e apps raisesTypeError: Context.__init__() got an unexpected keyword argument '_lock'. Copy only declared context fields or otherwise exclude_lock.AGENTS.md reference: framework/AGENTS.md:L113-L115
Useful? React with 👍 / 👎.