For a single python script you can use the
-u option, e.g.
python -u my_script.py
-u stands for "unbuffered". You can use the environment variable
PYTHONUNBUFFERED to set unbuffered I/O for your whole batch script.
#!/bin/bash#SBATCH -n 1export PYTHONUNBUFFERED=TRUEpython my_script.py
There is some performance penalty for having unbuffered print statements, so you may want to reduce the number of print statements, or run buffered for production runs.