modified: app.py
This commit is contained in:
12
app.py
12
app.py
@@ -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,9 +56,12 @@ 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']:
|
||||||
|
proc.terminate()
|
||||||
|
proc.wait()
|
||||||
|
print("Bot wurde gestoppt.")
|
||||||
bot_process = None
|
bot_process = None
|
||||||
else:
|
else:
|
||||||
print("Bot läuft nicht.")
|
print("Bot läuft nicht.")
|
||||||
|
|||||||
Reference in New Issue
Block a user