Reflex provides utility functions to help with common tasks in your applications.

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.

  • func: The non-async function to run in a separate thread.
  • The return value of the function.
  • ValueError: If the function is an async function.

run_in_thread Example

Use run_in_thread when you need to:

  1. Execute CPU-bound operations that would otherwise block the event loop
  2. Call synchronous libraries that don't have async equivalents
  3. Prevent long-running operations from blocking UI responsiveness

Built with Reflex