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
質問済み 1年前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日前

ログインしていません。 ログイン 回答を投稿する。

優れた回答とは、質問に明確に答え、建設的なフィードバックを提供し、質問者の専門分野におけるスキルの向上を促すものです。

質問に答えるためのガイドライン

関連するコンテンツ