AnswerDotAI / AnswerDotAI/fasthtml

invoking uvicorn from the main process doubles the main execution

Open
#497 0 comments 2 reactions 0 assignees View on GitHub
Dominant language
Jupyter Notebook
Stars
7k
Forks
319
Avg merge
28m
Merged PRs (30d)
3

Description

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

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.