Skip to content

Conversation

zbambergerNLP
Copy link
Contributor

When performing GEPA optimization using a pipeline that involves an embedder, the following error tends to occur:

Exception ignored in: <function Unbatchify.__del__ at 0x1263e0180>
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.

When performing GEPA optimization using a pipeline that involves an embedder, the following error tends to occur: 

```
Exception ignored in: <function Unbatchify.__del__ at 0x1263e0180>
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.
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR fixes an AttributeError that occurs during garbage collection of Unbatchify objects in GEPA optimization pipelines with embedders. The error happens when the destructor tries to access attributes that may not exist if the object was not fully initialized.

  • Adds a safety check in the __del__ method to verify object initialization before cleanup
  • Prevents AttributeError exceptions during garbage collection of partially initialized objects

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Ensures the worker thread is terminated when the object is garbage collected.
"""
self.close()
if hasattr(self, "batch_fn"):
Copy link
Preview

Copilot AI Sep 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fix checks for batch_fn but the error traceback shows the issue is with missing stop_event attribute. The check should verify the existence of stop_event instead, or check for multiple required attributes to ensure the object is fully initialized.

Suggested change
if hasattr(self, "batch_fn"):
if hasattr(self, "stop_event") and hasattr(self, "worker_thread"):

Copilot uses AI. Check for mistakes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant