Skip to content

Conversation

@masenf
Copy link
Collaborator

@masenf masenf commented Jan 21, 2026

This ensures that if the environment path is not correct, we should still be able to resolve the granian, gunicorn, and uvicorn modules when executing the server in a subprocess.

This ensures that if the environment path is not correct, we should still be
able to resolve the granian, gunicorn, and uvicorn modules when executing the
server in a subprocess.
@greptile-apps
Copy link
Contributor

greptile-apps bot commented Jan 21, 2026

Greptile Summary

This PR ensures reliable module resolution for external servers (uvicorn, gunicorn, granian) when launching production backends in subprocesses.

  • Added sys.executable -m prefix to all three backend server commands (run_uvicorn_backend_prod for Windows/Linux and run_granian_backend_prod)
  • This change ensures the servers are invoked using the current Python interpreter rather than relying on the system PATH, which may not include the correct environment bin directory
  • The pattern follows existing conventions in the codebase (e.g., scripts/hatch_build.py and reflex/custom_components/custom_components.py)

Confidence Score: 5/5

  • This PR is safe to merge with minimal risk - it's a small, focused fix that follows established patterns
  • The changes are minimal, well-understood, and follow an existing pattern used elsewhere in the codebase. Using sys.executable -m to invoke Python modules is a standard and reliable approach that improves subprocess module resolution.
  • No files require special attention

Important Files Changed

Filename Overview
reflex/utils/exec.py Added sys.executable -m prefix to uvicorn, gunicorn, and granian subprocess commands to ensure module resolution works regardless of PATH configuration. No issues found.

Sequence Diagram

sequenceDiagram
    participant App as Reflex App
    participant Exec as exec.py
    participant Proc as processes.new_process
    participant Subprocess as Python Subprocess

    App->>Exec: run_backend_prod()
    alt use granian
        Exec->>Exec: run_granian_backend_prod()
    else use uvicorn/gunicorn
        Exec->>Exec: run_uvicorn_backend_prod()
    end
    Exec->>Proc: new_process([sys.executable, "-m", "server", ...])
    Proc->>Subprocess: subprocess.run()
    Note over Subprocess: Server runs with<br/>correct Python interpreter
Loading

@codspeed-hq
Copy link

codspeed-hq bot commented Jan 21, 2026

Merging this PR will not alter performance

✅ 8 untouched benchmarks


Comparing masenf/exec-with-sys-executable (7dfce2a) with main (be43052)

Open in CodSpeed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants