modified: app.py
This commit is contained in:
12
app.py
12
app.py
@@ -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.")
|
||||
|
||||
Reference in New Issue
Block a user