modified: app.py
This commit is contained in:
29
app.py
29
app.py
@@ -1,4 +1,3 @@
|
|||||||
# web_panel/app.py
|
|
||||||
from flask import Flask, render_template, redirect, url_for, request, session
|
from flask import Flask, render_template, redirect, url_for, request, session
|
||||||
import os
|
import os
|
||||||
import subprocess
|
import subprocess
|
||||||
@@ -7,23 +6,33 @@ import psutil
|
|||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
app.secret_key = os.getenv("FLASK_SECRET_KEY", "default_secret_key")
|
app.secret_key = os.getenv("FLASK_SECRET_KEY", "default_secret_key")
|
||||||
|
|
||||||
|
# Speichern der Prozess-ID
|
||||||
|
bot_process = None
|
||||||
|
|
||||||
def bot_status():
|
def bot_status():
|
||||||
"""Überprüft, ob der Bot läuft."""
|
"""Überprüft, ob der Bot läuft."""
|
||||||
for proc in psutil.process_iter(['pid', 'name', 'cmdline']):
|
global bot_process
|
||||||
if 'python' in proc.info['name'] and 'bot.py' in proc.info['cmdline']:
|
if bot_process is None:
|
||||||
return True
|
return False
|
||||||
return False
|
return bot_process.poll() is None # None bedeutet, dass der Prozess noch läuft
|
||||||
|
|
||||||
def start_bot():
|
def start_bot():
|
||||||
"""Startet den Bot."""
|
"""Startet den Bot."""
|
||||||
subprocess.Popen(["python", "bot.py"], cwd=os.path.dirname(os.path.abspath(__file__)))
|
global bot_process
|
||||||
|
if not bot_status():
|
||||||
|
bot_process = subprocess.Popen(["python", "bot.py"], cwd=os.path.dirname(os.path.abspath(__file__)))
|
||||||
|
else:
|
||||||
|
print("Bot läuft bereits.")
|
||||||
|
|
||||||
def stop_bot():
|
def stop_bot():
|
||||||
"""Stoppt den Bot."""
|
"""Stoppt den Bot."""
|
||||||
for proc in psutil.process_iter(['pid', 'name', 'cmdline']):
|
global bot_process
|
||||||
if 'python' in proc.info['name'] and 'bot.py' in proc.info['cmdline']:
|
if bot_process and bot_status():
|
||||||
proc.terminate()
|
bot_process.terminate()
|
||||||
break
|
bot_process.wait() # Warten, bis der Prozess beendet ist
|
||||||
|
bot_process = None
|
||||||
|
else:
|
||||||
|
print("Bot läuft nicht.")
|
||||||
|
|
||||||
@app.route("/")
|
@app.route("/")
|
||||||
def index():
|
def index():
|
||||||
|
|||||||
Reference in New Issue
Block a user