Skip to content

Commit

Permalink
Start workers before stopping the old ones in respawn
Browse files Browse the repository at this point in the history
  • Loading branch information
gi0baro committed Apr 26, 2024
1 parent 4b3108d commit dfe1762
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions granian/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -374,15 +374,17 @@ def socket_loader():

for idx in workers:
self.respawned_procs[idx] = time.time()
proc = self.procs.pop(idx)
proc.terminate()
proc.join()
logger.info(f'Respawning worker-{idx + 1}')
old_proc = self.procs.pop(idx)
proc = self._spawn_proc(
idx=idx, target=spawn_target, callback_loader=target_loader, socket_loader=socket_loader
)
proc.start()
self.procs.insert(idx, proc)
time.sleep(delay)
logger.info(f'Stopping old worker-{idx + 1}')
old_proc.terminate()
old_proc.join()

def _stop_workers(self):
for proc in self.procs:
Expand Down

0 comments on commit dfe1762

Please sign in to comment.