MCPcopy
hub / github.com/benoitc/gunicorn / manage_workers

Method manage_workers

gunicorn/dirty/arbiter.py:908–929  ·  view source on GitHub ↗

Maintain the number of dirty workers.

(self)

Source from the content-addressed store, hash-verified

906 await DirtyProtocol.write_message_async(client_writer, response)
907
908 async def manage_workers(self):
909 """Maintain the number of dirty workers."""
910 if not self.alive:
911 return
912
913 num_workers = self.num_workers
914
915 # Spawn workers if needed
916 while self.alive and len(self.workers) < num_workers:
917 result = self.spawn_worker()
918 if result is None:
919 # No apps need more workers - stop spawning
920 break
921 await asyncio.sleep(0.1)
922
923 # Kill excess workers
924 while len(self.workers) > num_workers:
925 # Kill oldest worker
926 oldest_pid = min(self.workers.keys(),
927 key=lambda p: self.workers[p].age)
928 self.kill_worker(oldest_pid, signal.SIGTERM)
929 await asyncio.sleep(0.1)
930
931 def spawn_worker(self, force_all_apps=False):
932 """

Callers 5

_signal_handlerMethod · 0.95
_run_asyncMethod · 0.95
_worker_monitorMethod · 0.95
_handle_sigchldMethod · 0.95

Calls 3

spawn_workerMethod · 0.95
kill_workerMethod · 0.95
keysMethod · 0.45

Tested by 1