Label reflex child processes in `ps` (e.g. `reflex run [compiler]`)

Offen
#7,643 1 Kommentar 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Maintainer antworten meist innerhalb von 1 Tag

Dieses Issue hat noch niemand übernommen.

  • #7655 von @Akarshkushwaha — ohne Merge geschlossen

Bewertung

Schwierigkeit
3/5
Geschätzter Aufwand
Ein halber Tag
Anfängerfreundlichkeit
72/100
Issue-Typ
Feature
Klarheit
Klar beschrieben
Aktivitätsstatus
Aktiv
Tech-Stack
python

Rechercherichtung

Start with _compile_app_worker in reflex/reflex.py, the Granian(...) constructions in reflex/utils/exec.py, and the dependency in pyproject.toml. Add process titles for the compiler and relevant Granian services, then check uv run python scripts/check_min_deps.py and add the proposed helper tests, news fragment, and deployment documentation sentence. Done when child processes show their roles in process listings and every Granian construction passes an explicit title.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

enhancement

Describe the Enhancement you want

When reflex run starts, it spawns several child processes (the compiler worker, the Granian backend supervisor and its workers). They inherit the parent's command line, so ps auxww shows a wall of identical reflex run --frontend-port=3000 ... lines (or, with the spawn/forkserver start method, an unreadable python -c from multiprocessing.spawn import spawn_main; ... line). It would be much easier to tell them apart if each child set its own process title with a suffix naming its role:

root  5833  /usr/local/bin/python /usr/local/bin/reflex run --frontend-port=3000 --backend-port=8000 --loglevel=error
root  5853  /usr/local/bin/python /usr/local/bin/reflex run [compiler]
root  5916  /usr/local/bin/bun run dev
root  5917  node /home/user/app/.web/node_modules/.bin/react-router dev --host
root  5924  /usr/local/bin/python /usr/local/bin/reflex run [backend]
root  5925  /usr/local/bin/python /usr/local/bin/reflex run [backend] worker-1
  • Which feature do you want to improve? reflex run / reflex run --env prod process management.
  • What is the benefit? Debugging and ops: ps, top, htop and container process views immediately show which process is the compiler, the backend supervisor, or a worker, and which one is burning CPU or memory.

Where the processes come from

Child Spawned from Mechanism What ps shows today
Compiler reflex/reflex.py _compile_app ProcessPoolExecutor(max_workers=1); start method is fork, forkserver or spawn depending on platform / REFLEX_BACKEND_START_METHOD fork: parent's full command line; spawn/forkserver: python -c from multiprocessing.spawn ...
Backend supervisor + workers (dev and prod) reflex/utils/exec.py run_granian_backend, run_granian_backend_prod, run_frontend_prod Granian Server.serve(), workers via multiprocessing same as above, by start method
Backend, legacy uvicorn/gunicorn path (only when uvicorn is installed) run_uvicorn_backend, run_uvicorn_backend_prod uvicorn reload supervisor (spawn) or python -m gunicorn python -c ... / python -m gunicorn ...
Frontend dev server exec.py run_process_and_launch_url via processes.new_process subprocess.Popen(["bun", "run", "dev"]); bun then spawns node .../react-router dev --host already self-describing

Proposed implementation

Granian already supports this. granian.server.Server(process_name=...) sets the supervisor's title to process_name and each worker's title to f"{process_name} worker-{n}". It only needs the granian[pname] extra, which is the setproctitle package (prebuilt wheels for every CPython reflex supports, including 3.14). Without the extra, passing process_name raises ConfigurationError, so the dependency has to be unconditional rather than optional.

  1. In pyproject.toml, change granian[reload] >=2.7.4 to granian[reload,pname] >=2.7.4. Check that uv run python scripts/check_min_deps.py still passes.
  2. Add a small helper in reflex/utils/processes.py (or exec.py), e.g. set_process_title(label: str), that builds a title such as f"{sys.executable} {Path(sys.argv[0]).name} run [{label}]" and calls setproctitle.setproctitle(...). Keep the setproctitle import inside this one helper. Note that setproctitle replaces the whole title rather than appending, and under spawn the child's own argv is the -c bootstrap line, so constructing the title from scratch is the right approach for every start method.
  3. Call the helper at the top of _compile_app_worker in reflex/reflex.py with the label compiler. This function already runs inside the child. (Verified: with this call, fork, forkserver and spawn all show .../python3 reflex run [compiler].)
  4. Pass process_name= to the three Granian(...) constructions in reflex/utils/exec.py: the dev backend (ParentBoundGranian in run_granian_backend), run_granian_backend_prod, and the prod static frontend server (run_frontend_prod, which calls run_granian_backend_prod with its own app_target). Use labels like backend and frontend; Granian then names workers reflex run [backend] worker-1.
  5. Add a news fragment (news/+process-titles.feature.md), a unit test for the helper and for _compile_app_worker (monkeypatch setproctitle), and a sentence in the deployment docs mentioning that ps shows labeled processes.

Important: once setproctitle is importable, Granian's default title also changes, to granian asgi 0.0.0.0:8000 app:module for the supervisor and ... worker-1 for workers. So every Granian(...) call in reflex must pass process_name, otherwise the output changes in an unintended way.

Out of scope / caveats

  • bun / node frontend processes cannot be labeled from outside. exec -a "bun [frontend]" bun run dev does change argv[0] of the bun process on POSIX, but it needs a shell wrapper, does nothing for the node react-router dev grandchild (which is the one that actually uses CPU), and has no Windows equivalent. bun run dev is already recognisable, so leave it alone. Appending a literal [frontend] argument is not safe either, since bun run dev forwards extra arguments to the script.
  • The legacy uvicorn dev reload worker's only reflex-controlled entry point is the app factory, so labeling it would be hacky. Skip it. gunicorn in prod labels its own master and workers once setproctitle is installed.
  • prctl(PR_SET_NAME) only changes the 15-character comm field, not the args column, so it is not a substitute.
  • macOS: setproctitle works and ps shows the title; Activity Monitor keeps the original name.
  • Windows: setproctitle only sets the console window title; the command line in Task Manager is unchanged. Harmless, no gating needed, but no visible benefit.
  • On Linux the title is written over the original argv + environ block and is truncated beyond it. reflex run [compiler] is shorter than any realistic original command line, so this is not a practical concern.

Estimated effort: about half a day including tests.

Vorherrschende Sprache
Python
Sterne
29k
Forks
1.8k
Ø Merge
3 T. 5 Std.
Gemergte PRs (30 T.)
182

Entwicklungsumgebung

In Codespaces öffnen

Startet den Dev-Container des Projekts im Browser, mit Ihrem eigenen GitHub-Konto.

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus reflex-dev/reflex

Alle Issues in reflex-dev/reflex

Ähnliche Issues

Weitere Issues zu Python

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.