Allow threading for sync `use_effect` calls

Open
#1,136 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
35/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Stale
Tech stack
python
Domain
backend

Research direction

Start by tracing how sync use_effect calls are handled alongside the ASGI websocket consumer and document the current main-thread behavior. Define whether the default should serialize effects through a single worker, how the proposed threading parameter restores legacy behavior, and whether configurable worker counts are in scope; done requires an agreed design and corresponding coverage.

Written by the indexing model from the issue text.

Description

priority-2-moderate
Current Situation

Users frequently run into unexpected webserver "freezing" when using sync effects due to Python's single-threaded nature. This is seemingly caused by the ASGI websocket consumer being blocked from receiving/sending data during hook operations. This behavior doesn't seem to match up with equivalent JavaScript server side frameworks.

Proposed Actions

By default we should run all sync effects in a ThreadPoolExecutor(max_workers=1). This effectively runs all sync effects in a background thread. Additionally, by running all effects in the same worker thread (max_workers=1) this implementation is semi-threadsafe (as long as the user didn't start an operation outside of his use_effect call (which they shouldn't have under React-style programming). For operations that must run on the main thread, we need a @use_effect(threading: bool = ...) parameter to switch back to legacy behavior.

We could also consider a reactpy.config.USE_EFFECT_WORKERS=... setting to allow users to modify the value of max_workers.

Dominant language
Python
Stars
8.1k
Forks
332
PR merge metrics
No merged PRs in 30d

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from reactive-python/reactpy

All issues in reactive-python/reactpy

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.