Python Flask Server send_file fails when SSH terminal disconnected

0

I think this would be a useful question to others too.

I have a flask server running (on an EC2) and delivers attachments via python send_file as a request. Works great. It also provides a list of the files available. (Using your browser). The process is I SSH to the terminal start the python3 minflask.py &

I exit the SSH. All commands work for the minflask.py accept the send_file which says server error. I know the process is running. I can SSH again and see the process is running.

So instead (what works) the process is

SSH for the terminal tmux new -s mywindow python3 minflask.py

and all works. I close the SSH terminal and all works fine. Later I can tmux a -t mywindow and see my Flask server output information.

So what is the real issue HERE?

I have tried send_file with an fp=open and send_from_directory and so on. No difference. I know I can open files.

redpath
gefragt vor einem Jahr42 Aufrufe
1 Antwort
0

The issue may be in the keepalive settings of your app. Or better the timeout of the sessions where your app stands in. Usually you would use a screen function on Linux to keep the session up even if your not logged.

Try to modify your supervisord as follows to mimick tmux or screen functions.

[program:minflask]
command=python3 minflask.py
directory=/path/to/your/app
autostart=true
autorestart=true
stderr_logfile=/var/log/minflask.err.log
stdout_logfile=/var/log/minflask.out.log
profile picture
EXPERTE
beantwortet vor 5 Tagen

Du bist nicht angemeldet. Anmelden um eine Antwort zu veröffentlichen.

Eine gute Antwort beantwortet die Frage klar, gibt konstruktives Feedback und fördert die berufliche Weiterentwicklung des Fragenstellers.

Richtlinien für die Beantwortung von Fragen