uvicorn icon indicating copy to clipboard operation
uvicorn copied to clipboard

New multiprocess manager

Open abersheeran opened this issue 2 years ago • 7 comments

Summary

About https://github.com/encode/uvicorn/discussions/2164.

The multiprocess manager introduced by this PR includes process keep-alive and process hung detection. It also imitates gunicorn and uses hup, ttin, and ttou signals to control child processes.

Checklist

  • [x] I understand that this PR may be closed in case there was no previous discussion. (This doesn't apply to typos!)
  • [x] I've added a test for each change that was introduced, and I tried as much as possible to make a single atomic change.
  • [x] I've updated the documentation accordingly.

abersheeran avatar Dec 15 '23 03:12 abersheeran

@abersheeran I'm fully available to move this forward. šŸ‘

Kludex avatar Mar 02 '24 13:03 Kludex

Pinging @ahopkins to review the initial steps since he offered helped on #2164. šŸ™

Kludex avatar Mar 03 '24 08:03 Kludex

Ok. šŸ‘

We can move forward with the checklist above šŸ™

Kludex avatar Mar 04 '24 08:03 Kludex

I see what the PR is doing, but I somewhat fail to understand the why and the goals. Is the pinging the ultimate feature add here?

The goal is to not suggest people to use Gunicorn anymore.

Kludex avatar Mar 04 '24 11:03 Kludex

Next I will submit tests and documentation. If anyone can help, please commit directly to the branch of this PR... This will be a long and painful process. /(愒o愒)/~~

abersheeran avatar Mar 05 '24 02:03 abersheeran

Also, if I press CTRL + C on uvicorn main:app --workers 2, it doesn't work as expected.

Kludex avatar Apr 13 '24 10:04 Kludex

Also, if I press CTRL + C on uvicorn main:app --workers 2, it doesn't work as expected.

Can you try the latest commit version? This should solve the problem.

abersheeran avatar Apr 14 '24 08:04 abersheeran

I think the PID should be shown in the "uvicorn.access" logger (only when workers > 1).

Is it normal for the child processes to be alive after I kill the manager process?

Kludex avatar May 26 '24 08:05 Kludex

I think the PID should be shown in the "uvicorn.access" logger (only when workers > 1).

Here I just reused the previous logger. If we want to refactor the logs, I think it can be done in another PR.

Is it normal for the child processes to be alive after I kill the manager process?

No, normally only killing the manager process through the SIGKILL signal will result in the survival of child processes (this is due to system signal mechanism reasons, and it also exists in all other multi-process managers), under other circumstances, child processes should be killed.

abersheeran avatar May 26 '24 12:05 abersheeran

Thanks @abersheeran šŸ™

Kludex avatar May 28 '24 06:05 Kludex