Skip to content

Commit

Permalink
only watch signal if main thread (#152)
Browse files Browse the repository at this point in the history
  • Loading branch information
bboynton97 authored Apr 17, 2024
1 parent b8fccc9 commit a1c998d
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions agentops/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import atexit
import signal
import sys
import threading

from .meta_client import MetaClient
from .config import Configuration, ConfigurationError
Expand Down Expand Up @@ -293,11 +294,13 @@ def handle_exception(exc_type, exc_value, exc_traceback):
# 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):
Expand Down

0 comments on commit a1c998d

Please sign in to comment.