Background: I've noticed that the trick nohup python test.py & usually doesn't work because the output is not saved correctly in real-time in nohup.out. The solutions given in this famous question (such as nohup python -u) don't always work, as shown in my other question here.
Question: I have used print(...) everywhere in my code, so I don't want to change this and replace it by another logging function. Is it possible to redefine print to do this instead:
from __future__ import print_function
def print(s):
    with open('out.txt', 'a+') as f:
        f.write(str(s) + '\n')
    old_print(s)     # how to print it with the standard print too?