Forcing unbuffered writing in a Python file
Sometimes writing (to text files and on screen) is not done on the fly, but at the end of the script. In this case, you need to force writing by flushing the memory buffer. So we’ll use the print method defined here:
import os,sys,builtins
def print(text):
print(text)
builtins.
os.fsync(sys.stdout)
def print2(text1,text2):
print(text1, text2)
builtins.
os.fsync(sys.stdout)
=open("readgrib.txt","a",buffering=1)
sys.stdout
# script avec des calculs et des print
print('read grdfile') # avec un argument
'read grdfile', gridname) # avec deux arguments
print2(# et autre print....