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
preguntada hace un año42 visualizaciones
1 Respuesta
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
EXPERTO
respondido hace 5 días

No has iniciado sesión. Iniciar sesión para publicar una respuesta.

Una buena respuesta responde claramente a la pregunta, proporciona comentarios constructivos y fomenta el crecimiento profesional en la persona que hace la pregunta.

Pautas para responder preguntas