modified: app.py

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

14
app.py
View File

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