Skip to content

Commit

Permalink
fix(api): attempt to recycle leaking workers when a job finishes
Browse files Browse the repository at this point in the history
  • Loading branch information
ssube committed Mar 6, 2023
1 parent 3a4928e commit 4ae4ce1
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions api/onnx_web/worker/pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ def finished_worker(finished: Queue):
_device, progress = self.active_jobs[job]
self.finished_jobs.append((job, progress, context.cancel.value))
del self.active_jobs[job]
self.join_leaking()
except Empty:
pass
except ValueError:
Expand Down Expand Up @@ -262,6 +263,7 @@ def join(self):
queue.close()

self.pending.clear()
self.join_leaking()

logger.debug("stopping device workers")
for device, worker in self.workers.items():
Expand All @@ -282,9 +284,7 @@ def join(self):

logger.debug("worker pool stopped")

def recycle(self):
logger.debug("recycling worker pool")

def join_leaking(self):
if len(self.leaking) > 0:
logger.warning("cleaning up %s leaking workers", len(self.leaking))
for device, worker in self.leaking:
Expand All @@ -297,6 +297,10 @@ def recycle(self):

self.leaking[:] = [dw for dw in self.leaking if dw[1].is_alive()]

def recycle(self):
logger.debug("recycling worker pool")
self.join_leaking()

needs_restart = []

for device, worker in self.workers.items():
Expand Down

0 comments on commit 4ae4ce1

Please sign in to comment.