Skip to content

Commit 801d45e

Browse files
committed
Add docstring for run_in_thread
To: - clarify the behavior - add note that it won't work with inline functions - lambdas and closures.
1 parent 694d336 commit 801d45e

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

py/gooey_gui/core/state_interactions.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,21 @@ def run_in_thread(
4747
key: str | None = None,
4848
ex=60,
4949
):
50+
"""
51+
Creates a new thread to run `fn(*args, **kwargs)`.
52+
53+
Returns:
54+
- `None` until the function call is executing.
55+
- The returned value of `fn(*args, **kwargs)` on the next call.
56+
If `cache=True`, the same value will be cached in the `session_state`.
57+
Further calls to `run_in_thread(fn, ...)` will return the same value
58+
until the `session_state` is reset (e.g. with a page refresh).
59+
60+
Note that `fn.__name__` is used in the cache key. Because of this,
61+
it won't work with `lambda`s and closures that don't have a fixed
62+
value for `__name__`.
63+
"""
64+
5065
if key is None:
5166
key = f"{run_in_thread.__name__}/{fn}"
5267

0 commit comments

Comments
 (0)