Utility Functions
Reflex provides utility functions to help with common tasks in your applications.
run_in_thread
The run_in_thread
function allows you to run a non-async function in a separate thread, which is useful for preventing long-running operations from blocking the UI event queue.
Parameters
func
: The non-async function to run in a separate thread.
Returns
- The return value of the function.
Raises
ValueError
: If the function is an async function.
Usage
run_in_thread Example
When to Use run_in_thread
Use run_in_thread
when you need to:
- Execute CPU-bound operations that would otherwise block the event loop
- Call synchronous libraries that don't have async equivalents
- Prevent long-running operations from blocking UI responsiveness