fasthtml icon indicating copy to clipboard operation
fasthtml copied to clipboard

invoking uvicorn from the main process doubles the main execution

Open dan-hoog opened this issue 4 months ago • 0 comments

Working with FastHTML and loving it so far.

I realized that using the embedded invocation of uvicorn via serve() from the top process causes the primary code to execute twice (from within the same process).

This was mostly harmless (duplicated log records in an activity table) but undesired in my instance. It is unrelated to running multiple parallel server instances.

When run under uvicorn with "uvicorn --port 5001 fasthtml_test:app" the main logic only executes once.

I first observed in more complex logic, but saw the behavior in your simple example as well. Here is snippet of initial sample modified to show this behavior with print()...

from fasthtml.common import FastHTML, serve import os

app = FastHTML()

print(f'fasthtml_test loaded os_getpid={os.getpid()}') @app.get("/") def home(): return "

Hello, World

"

serve()

dan-hoog avatar Oct 07 '24 02:10 dan-hoog