From ca77530dd4be84577bf00372ba67b0aac489604a Mon Sep 17 00:00:00 2001 From: Zach Bamberger <94684184+zbambergerNLP@users.noreply.github.com> Date: Tue, 9 Sep 2025 19:52:20 -0700 Subject: [PATCH] Check for batch_fn before calling close When performing GEPA optimization using a pipeline that involves an embedder, the following error tends to occur: ``` Exception ignored in: Traceback (most recent call last): File "/Users/zachbam/.local/share/mise/installs/python/3.12.11/lib/python3.12/site-packages/dspy/utils/unbatchify.py", line 112, in __del__ self.close() File "/Users/zachbam/.local/share/mise/installs/python/3.12.11/lib/python3.12/site-packages/dspy/utils/unbatchify.py", line 92, in close if not self.stop_event.is_set(): ^^^^^^^^^^^^^^^ AttributeError: 'Unbatchify' object has no attribute 'stop_event' ``` The issue seems to stem from instances where deletion is called, but the object is already gone. My suggested fix resolves this issue. --- dspy/utils/unbatchify.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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()