Exerpt I have a webpage with a single button on it under a POST form:
<form method="post">
<button type="submit" class="btn btn-outline-primary">START</button>
</form>
And in the Flask app I have a function that listens for incoming traffic (a while loop):
@app.route('/status', methods=['GET', 'POST'])
@requires_login
def status():
if request.method == 'POST':
print("INIT 1 HIT")
data = Database.find('site')
host = data[0]['host']
port = data[0]['port']
while True:
xml = xml_builder.generate_xml()
if xml:
print(xml)
len_xml = len(xml)
header = connection.ip_header(len_xml)
connection.send_tcp(host, port, header, xml)
return render_template('user/panel.html')
The problem is, once I press the button the page will start loading and going inside the infinite loop. Thus, never hitting return render_template.
uWSGI sees this as a timeout, and after 60 seconds will restart my app and I will lose the active listening for traffic from the while loop.
I read the official uWSGI documentation about reload-mercy, worker-reload-mercy, mule-reload-mercy, min-worker-lifetime, harakiri, and die-on-term for the uwsgi.ini file, but non of those seemed to be helping with anything and it also seems a bit like a hack.
My question is, how can I keep running the loop in the background without the page reloading or How can I actively listen for traffic in the background once the button is pressed and how can I still keep it running even after closing the browser?
The setup is working on a RaspberryPI connected by serial to an external device.