Skip to content

Commit

Permalink
A better way to ensure pipeline closed successfully. (#80)
Browse files Browse the repository at this point in the history
  • Loading branch information
scott306lr authored Mar 1, 2024
1 parent d977c82 commit 693f255
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions pycoral/pipeline/pipelined_model_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,15 @@ def __init__(self, interpreters):
def __del__(self):
if self._runner:
# Push empty request to stop the pipeline in case user forgot.
self.push({})
num_unconsumed = 0
try:
print("Push empty request to stop the pipeline...")
self.push({})
except RuntimeError:
print("The pipeline has already been closed successfully.")
return

# Release any unconsumed tensors if any.
num_unconsumed = 0
while self.pop():
num_unconsumed += 1
if num_unconsumed:
Expand Down

0 comments on commit 693f255

Please sign in to comment.