Skip to content
This repository was archived by the owner on Jul 8, 2023. It is now read-only.

Commit 22d14bb

Browse files
committed
Handle KeyboardInterrupt exception
1 parent 5b726b5 commit 22d14bb

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

project/tenhou/client.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,13 @@ def _send_keep_alive_ping(self):
377377
def send_request():
378378
while self.game_is_continue:
379379
self._send_message('<Z />')
380-
sleep(15)
380+
381+
# we can't use sleep(15), because we want to be able
382+
# end thread in the middle of running
383+
seconds_to_sleep = 15
384+
for x in range(0, seconds_to_sleep * 2):
385+
if self.game_is_continue:
386+
sleep(0.5)
381387

382388
self.keep_alive_thread = Thread(target=send_request)
383389
self.keep_alive_thread.start()

project/tenhou/main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,5 @@ def connect_and_play():
2525
else:
2626
client.end_game()
2727
except KeyboardInterrupt:
28-
logger.info('Ending the game... can take 15 seconds')
28+
logger.info('Ending the game...')
2929
client.end_game()

0 commit comments

Comments
 (0)