I'm doing a Python webserver (e.g. using Flask or Bottle, etc.), and I would like to start it, and be able to close the SSH terminal and let it running.
Which way would be the pythonic recommended way to do it?
- Create a daemon, and use - python myapp.py start,- python myapp.py stop. However the python-daemon module has nearly no doc, doesn't support triggering an action just before exiting (I added a few lines to it to support it), so it's a bit a hack of an undocumented/not-really-maintained module, so even if it works, I'm not 100% happy with it.
- Use - nohup python myapp.py &, but then the drawback is that you have to- ps aux |grep py, then find the relevant PID and- kill 12345to stop it. Here again, it doesn't allow to do actions before stopping (e.g. save the database to disk, etc.), so it's not a very nice solution.
- screen -dmS myapp python myapp.pyto start, then you can log out from SSH terminal. Then later you can connect to it again with- screen -r myapp, and then CTRL+C can stop it (provided- KeyboardInterruptis well handled). That's what I would use currently. But I'm not sure if using- screento let a server run forever is a good idea (what happens if the logging is really verybose? also is there a risk that introducing the- screenlayer would make it bloated?)
- Another cleaner solution? I hope there's a cleaner solution than 1, 2, 3 that all have drawbacks. 
Note: I would like to avoid installing new managers (upstart or supervisor), and do it with the least number of tools possible, to avoid new layers of complexity.
