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
Hypercorn runs with duplicated process #88
Comments
I just provided a minimal example to reproduce the problem in the first post. Anybody any idea? |
I guess that is because hypercorn fork before import, while uvicorn import first. |
Am I doing something wrong? |
This is expected - is it causing a problem? (Hypercorn runs with a minimum of 2 processes). |
Well, yes, it causing a problem, as it executes two times the same procedure in parallel, which should be executed only once... |
Is there any option which forces hypercorn to run only with one process? |
What does it actually execute twice though? I think it will log twice, but only one app worker will run - the other worker manages the reloading. |
In the real application the main module includes some other modules, and some of the other modules start a separate thread (kind of background service). |
Ah, I see. I would consider it problematic for a module to create side effects (start a thread) when imported. Instead I suggest you start the thread actively and place that call within a startup function. If you are using Quart you can do something like this, @app.before_serving
async def startup():
start_background_service() Edit: I see you are using FastAPI, in which case you can use a startup event https://fastapi.tiangolo.com/advanced/events/ |
OK, it looks like a reasonable solution, thank you very much for your support. |
Hi all,
I am not sure whether this is really hypercorn issue, but could not imagine what else can be so please bear with me.
I am running a server with hypercorn on Ubuntu 20.04.
The problem is that it is runs with a duplicated process in background.
The main process is 2278497, but there are duplicated processes 2278499 and 2278450.
This causes unwanted effects by executing twice the same tasks.
How can I avoid that?
EDIT
A minimal example:
I then type:
sudo hypercorn test_main:app
and the stdout is:
If I use uvicorn the message is printed only one time, as expected:
The text was updated successfully, but these errors were encountered: