Skip to content

Add docstring for run_in_thread #53

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions py/gooey_gui/core/state_interactions.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,21 @@ def run_in_thread(
key: str | None = None,
ex=60,
):
"""
Creates a new thread to run `fn(*args, **kwargs)`.

Returns:
- `None` until the function call is executing.
- The returned value of `fn(*args, **kwargs)` on the next call.
If `cache=True`, the same value will be cached in the `session_state`.
Further calls to `run_in_thread(fn, ...)` will return the same value
until the `session_state` is reset (e.g. with a page refresh).

Note that `fn.__name__` is used in the cache key. Because of this,
it won't work with `lambda`s and closures that don't have a fixed
value for `__name__`.
"""

if key is None:
key = f"{run_in_thread.__name__}/{fn}"

Expand Down