Handle keyboard interrupts properly.
This commit is contained in:
parent
58ca231454
commit
bb6b157774
1 changed files with 14 additions and 8 deletions
22
main.py
22
main.py
|
@ -4,6 +4,7 @@ import subprocess
|
||||||
import logging
|
import logging
|
||||||
import sys
|
import sys
|
||||||
import time
|
import time
|
||||||
|
import psutil
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
logger.setLevel(logging.DEBUG)
|
logger.setLevel(logging.DEBUG)
|
||||||
|
@ -21,11 +22,16 @@ def start_bot():
|
||||||
|
|
||||||
|
|
||||||
bot = start_bot()
|
bot = start_bot()
|
||||||
while True:
|
try:
|
||||||
if bot.poll() is not None:
|
while True:
|
||||||
if bot.returncode == 26:
|
if bot.poll() is not None:
|
||||||
logger.info("exit code 26 received, restarting bot!")
|
if bot.returncode == 26:
|
||||||
bot = start_bot()
|
logger.info("exit code 26 received, restarting bot!")
|
||||||
else:
|
bot = start_bot()
|
||||||
break
|
else:
|
||||||
time.sleep(1) # keeps code from overworking.
|
break
|
||||||
|
time.sleep(1) # keeps code from overworking.
|
||||||
|
except KeyboardInterrupt:
|
||||||
|
print("Killing Bot Process")
|
||||||
|
psutil.Process(bot.pid).kill()
|
||||||
|
print("Killed successfully")
|
||||||
|
|
Loading…
Reference in a new issue