diff --git a/dspy/utils/unbatchify.py b/dspy/utils/unbatchify.py index 44a4f59504..789229792a 100644 --- a/dspy/utils/unbatchify.py +++ b/dspy/utils/unbatchify.py @@ -109,4 +109,5 @@ def __del__(self): """ Ensures the worker thread is terminated when the object is garbage collected. """ - self.close() + if hasattr(self, "batch_fn"): + self.close()