Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

only watch signal if main thread #152

Merged
merged 1 commit into from
Apr 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading