Skip to content

Commit

Permalink
fix(client.py): add concurrency flag to SIGINT handler to prevent bei…
Browse files Browse the repository at this point in the history
…ng handled multiple times

Fixes #477
  • Loading branch information
teocns committed Oct 31, 2024
1 parent 4ce6f80 commit ce22283
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions agentops/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,8 @@ def cleanup(end_state: str = "Fail", end_state_reason: Optional[str] = None):
end_state_reason=end_state_reason,
)

__handled = False

def signal_handler(signum, frame):
"""
Signal handler for SIGINT (Ctrl+C) and SIGTERM. Ends the session and exits the program.
Expand All @@ -326,6 +328,10 @@ def signal_handler(signum, frame):
signum (int): The signal number.
frame: The current stack frame.
"""
nonlocal __handled
if __handled:
return
__handled = True
signal_name = "SIGINT" if signum == signal.SIGINT else "SIGTERM"
logger.info("%s detected. Ending session...", signal_name)
self.end_session(
Expand Down

0 comments on commit ce22283

Please sign in to comment.