Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

invoking uvicorn from the main process doubles the main execution #497

Open
dan-hoog opened this issue Oct 7, 2024 · 0 comments
Open

invoking uvicorn from the main process doubles the main execution #497

dan-hoog opened this issue Oct 7, 2024 · 0 comments

Comments

@dan-hoog
Copy link

dan-hoog commented Oct 7, 2024

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()

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

No branches or pull requests

1 participant