Skip to content

Commit

Permalink
Fix settings.context finally block: main_thread_config
Browse files Browse the repository at this point in the history
  • Loading branch information
okhat committed Nov 24, 2024
1 parent 5c2ee6a commit 21ab3bb
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion dsp/utils/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class Settings:
def __new__(cls):
if cls._instance is None:
cls._instance = super().__new__(cls)
cls._instance.lock = threading.Lock() # maintained here for assertions
# No need for a lock since we're only updating main_thread_config in the main thread
return cls._instance

def __getattr__(self, name):
Expand Down Expand Up @@ -113,6 +113,10 @@ def context(self, **kwargs):
finally:
dspy_ctx_overrides.reset(token)

if threading.current_thread() is threading.main_thread():
global main_thread_config
main_thread_config = dspy_ctx_overrides.get()

def __repr__(self):
overrides = dspy_ctx_overrides.get()
combined_config = {**main_thread_config, **overrides}
Expand Down

0 comments on commit 21ab3bb

Please sign in to comment.