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
질문됨 일 년 전42회 조회
1개 답변
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
전문가
답변함 5일 전

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠