gunicorn icon indicating copy to clipboard operation
gunicorn copied to clipboard

Reap workers in the main loop

Open tilgovi opened this issue 4 years ago • 13 comments

Handle SIGCHLD like every other signal, waking up the arbiter and handling the signal in the main loop rather than in the signal handler.

Take special care to reinstall the signal handler in case Python avoided doing so to prevent infinite recursion.

Clean up workers and call the worker_exit hook in only one place. When killing a worker, do not clean it up. The arbiter will now clean up the worker and invoke the hook when it reaps the worker.

With reaping handled in the main loop and kill_worker delegating responsibility for cleanup to the reaping loop, iterate over the workers dictionary everywhere else without concern for concurrent modification.

tilgovi avatar Apr 20 '20 23:04 tilgovi