Handle keyboard interrupts properly.

This commit is contained in:
InValidFire 2021-03-31 14:53:01 -04:00
parent 58ca231454
commit bb6b157774
1 changed files with 14 additions and 8 deletions

22
main.py
View File

@ -4,6 +4,7 @@ import subprocess
import logging
import sys
import time
import psutil
logger = logging.getLogger(__name__)
logger.setLevel(logging.DEBUG)
@ -21,11 +22,16 @@ def start_bot():
bot = start_bot()
while True:
if bot.poll() is not None:
if bot.returncode == 26:
logger.info("exit code 26 received, restarting bot!")
bot = start_bot()
else:
break
time.sleep(1) # keeps code from overworking.
try:
while True:
if bot.poll() is not None:
if bot.returncode == 26:
logger.info("exit code 26 received, restarting bot!")
bot = start_bot()
else:
break
time.sleep(1) # keeps code from overworking.
except KeyboardInterrupt:
print("Killing Bot Process")
psutil.Process(bot.pid).kill()
print("Killed successfully")