Skip to content

Explicit thread pool executor for sync event handlers #6225

Open

Description

@masenf

Summary

Move sync EventHandler execution to an explicit thread pool executor. The @rx.event decorator should accept an optional executor kwarg that determines which executor (or the default) is used to run the function.

There should be a new default_executor field in rx.Config that accepts either a ThreadPoolExecutor or a string pointing to an importable ThreadPoolExecutor or function that returns a ThreadPoolExecutor.

Passing None for the executor will just run the function on the event processing thread like before (no immediate behavior change, must opt in)

Details

Sync functions get wrapped in loop.run_in_executor() transparently, so callers always await regardless of whether the underlying function is sync or async. This aligns with the EventHandler redesign where every handler is simply awaitable.

Custom executors allow tuning:

  • A CPU-bound handler can use a ProcessPoolExecutor
  • A DB-heavy handler can use a dedicated thread pool with limited concurrency
  • Default executor handles the common case

This largely eliminates the most common source of event loop blocking — sync handlers that do I/O or CPU work on the main thread.

Related

  • Works in tandem with event loop blocking detection (Linear ENG-6436) — if a sync handler accidentally bypasses the executor, blocking detection catches it.

Part of the Reflex Framework Roadmap — Section 1c.

Activity

  1. added
    enhancement
    on Mar 25, 2026
  2. linear commented on Mar 25, 2026

    @linear
  3. self-assigned this
    on Jul 12, 2026
  4. added
    roadmap
    on Oct 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

enhancementroadmap

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions