Systemd StandardOutput not working with python script

If you need to define a Systemd service that run a python script and save standard out to a file, you need to be aware of an (for me) unexpected problem. It seemed easy. Using a recent version of systemd, the following setting should output the standard output to the log file.


It didn't and I used quite some time to debug it. Then I found this answer: Stackoverflow and the solution is to add


to the unit file. This way no output to stdout is buffered. Another way to turn off buffering is to add -u to the python call.

Exec=python -u