From 693f255d4638afbd98b4b52507bb9b5fdbaa901c Mon Sep 17 00:00:00 2001 From: scott306lr <58700182+scott306lr@users.noreply.github.com> Date: Fri, 1 Mar 2024 22:53:48 +0800 Subject: [PATCH] A better way to ensure pipeline closed successfully. (#80) --- pycoral/pipeline/pipelined_model_runner.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/pycoral/pipeline/pipelined_model_runner.py b/pycoral/pipeline/pipelined_model_runner.py index ee92f0d..fbbec65 100644 --- a/pycoral/pipeline/pipelined_model_runner.py +++ b/pycoral/pipeline/pipelined_model_runner.py @@ -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: