Skip to content

Python SDK for AI agent monitoring, LLM cost tracking, benchmarking, and more. Integrates with most LLMs and agent frameworks including CrewAI, Agno, OpenAI Agents SDK, Langchain, Autogen, AG2, and CamelAI

only watch signal if main thread (#152)

Braelyn Boyntona1c998da72da
diff --git a/agentops/client.py b/agentops/client.py
index 339a2013..69998765 100644
--- a/agentops/client.py
+++ b/agentops/client.py
@@ -19,6 +19,7 @@ import inspect
import atexit
import signal
import sys
+import threading
from .meta_client import MetaClient
from .config import Configuration, ConfigurationError
@@ -293,11 +294,13 @@ class Client(metaclass=MetaClient):
# Then call the default excepthook to exit the program
sys.__excepthook__(exc_type, exc_value, exc_traceback)
- atexit.register(lambda: cleanup(end_state="Indeterminate",
- end_state_reason="Process exited without calling end_session()"))
- signal.signal(signal.SIGINT, signal_handler)
- signal.signal(signal.SIGTERM, signal_handler)
- sys.excepthook = handle_exception
+ # if main thread
+ if isinstance(threading.current_thread(), threading._MainThread):
+ atexit.register(lambda: cleanup(end_state="Indeterminate",
+ end_state_reason="Process exited without calling end_session()"))
+ signal.signal(signal.SIGINT, signal_handler)
+ signal.signal(signal.SIGTERM, signal_handler)
+ sys.excepthook = handle_exception
@property
def current_session_id(self):