modified: app.py

This commit is contained in:
SimolZimol
2024-09-06 16:43:52 +02:00
parent bbee4f0e61
commit 6170ad8cd7

12
app.py
View File

@@ -45,9 +45,8 @@ def bot_status():
return True
return False
def start_bot():
"""Startet den Bot."""
"""Startet den Bot, falls er nicht bereits läuft."""
global bot_process
if not bot_status():
bot_process = subprocess.Popen(["python", "bot.py"], cwd=os.path.dirname(os.path.abspath(__file__)))
@@ -57,9 +56,12 @@ def start_bot():
def stop_bot():
"""Stoppt den Bot."""
global bot_process
if bot_process and bot_status():
bot_process.terminate()
bot_process.wait() # Warten, bis der Prozess beendet ist
if bot_status():
for proc in psutil.process_iter(['pid', 'name', 'cmdline']):
if 'python' in proc.info['name'] and 'bot.py' in proc.info['cmdline']:
proc.terminate()
proc.wait()
print("Bot wurde gestoppt.")
bot_process = None
else:
print("Bot läuft nicht.")