简体   繁体   中英

Python / Flask background process dies

NB. This is a repost of the question. My original post was closed because someone thought I asked about how I could configure a Flask app for production or to run in background. This is not the question. The question is why the python background process suddenly dies.

I am running a Flask application on Ubuntu (using development server) with the following command line:

python myflaskapp.py > log.txt 2>&1 &

After I log off the ssh session - it runs fine for a while but then suddenly the process dies. There are no requests to it that causes it either. It just dies. The application is really simple. There are no DB connections or anything. It just receives some file upload and uses XLRD to convert it to csv. But it dies after a while even if no requests are sent to it.

Any ideas what causes this? Any way of logging it? There are no log entries in log.txt that shows whats going on either.

I know that I am not supposed to run development server for production, and I am running it also in gunicorn now - but I would really like to know why the Python process dies.

I have another Flask application and that one "lives forever". It is built in the same way - but that process will live until the computer boots or some unhandled exception occurs.

I think I found the issue here. It seems that systemd is killing the session after some time - even if running the process in background.

There are (at least) two solutions:

  • Set KillUserProcesses=No in logind.conf
  • Run as systemd service instead

https://fedoraproject.org/wiki/Changes/KillUserProcesses_by_default

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM