1, run-time plus-u parameters, such as # python3-u test.py >> Test.log &
View Python's-u parameter with man, as described below:
Force stdin, stdout and stderr to be totally unbuffered. On the systems where it matters, also put stdin, stdout and stderr in binary mode. Note that there was internal buffering in Xreadlines (), ReadLines () and File-object iterators ("for line in Sys.stdin") whi CH is isn't influenced by this option. To work around this, you'll want to the use of "sys.stdin.readline ()" Inside a "while 1:" Loop.
Force Stdin,stdout and stderr to be completely unbuffered.
2. Add the Sys.stdout.flush () function after each print that does not buffer
3, the script header add-u, such as #!/usr/local/bin/python-u, the same method 1
4. Add environment variable Pythonunbuffered=1
Python background execution does not enable caching