Running a Selenium script through Flask application hosted on Waitress server, but it completes execution within a second, thus closing the automatically opened browser within a second, and further failing the script. It works totally fine when ran through Flask's development server in debug mode. There's no error printed or logged anywhere in the system.
Here's the code snippet for the flask app -
def index():
return render_template('index.html', event_id=get_latest_event_id(),historical_executions=historical_executions)
def run_script():
try:
print("Request received to run the script")
script_path = 'EmailResults.py'
result = subprocess.run(['python', script_path], cwd = '.', capture_output=True, text=True)
Index.html code that triggers the script's execution with a button click -
runScriptButton.addEventListener("click", function() {
fetch("/run_script", {
method: "POST"
})
Tried adding explicit waits but that didn't help. Tried using a different hosting server gunicorn but it resulted into the same 1 second execution. Googling for help suggested adding multiple explicit waits in the script, but that didn't help. And I am not sure about the purpose of adding these waits, since the Selenium script itself works totally fine on a standalone or Flask's debug mode basis.
I expect the script to run successfully, the way it does when ran through Flask's local server in debug mode. Please help, thank you in advance.