Cron job seems to be running but no output and got killed after a while

Solution 1:

I suspect it's because when the output is redirected, python3 buffers its standard output stream - and the buffer is not getting flushed when the process is killed.

To illustrate, given

$ cat file2.py
import time
print(2)
time.sleep(5)

then

$ timeout 3 python3 file2.py
2

whereas

$ timeout 3 python3 file2.py | cat
Terminated

If you force python3 to unbuffer its streams you will likely see the expected log output:

$ timeout 3 python3 -u file2.py | cat
2
Terminated