Skip to content

Commit dba17f8

Browse files
authored
Fix signal handler for soft-quitting lichess-bot (#1156)
* Delete condition that is always False * Remove terminated condition from API giveup
1 parent c591231 commit dba17f8

2 files changed

Lines changed: 3 additions & 6 deletions

File tree

lib/lichess.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ def get_challenge_timeout(challenge_response: ChallengeType) -> datetime.timedel
105105
def is_final(exception: Exception) -> bool:
106106
"""If `is_final` returns True then we won't retry."""
107107
return (isinstance(exception, HTTPError) and exception.response is not None and exception.response.status_code < 500
108-
or stop.terminated or stop.force_quit)
108+
or stop.force_quit)
109109

110110

111111
def backoff_handler(details: BackoffDetails) -> None:

lib/lichess_bot.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -88,14 +88,11 @@ def disable_restart() -> None:
8888

8989
def signal_handler(signal: int, frame: FrameType | None) -> None: # noqa: ARG001
9090
"""Terminate lichess-bot."""
91-
in_starting_thread = __name__ == "__main__"
9291
if not stop.terminated:
93-
if in_starting_thread:
94-
logger.debug("Received SIGINT. Terminating client.")
92+
logger.debug("Received SIGINT. Terminating client.")
9593
stop.terminated = True
9694
else:
97-
if in_starting_thread:
98-
logger.debug("Received second SIGINT. Quitting now.")
95+
logger.debug("Received second SIGINT. Quitting now.")
9996
stop.force_quit = True
10097

10198

0 commit comments

Comments
 (0)