Application Guide: Python¶
This page contains information on Python, specifically in relation to how it functions on BlueBEAR.
Python Output Buffering¶
Python buffers its output by default, which can be problematic if running a batch job on BlueBEAR (i.e. submitting a job using sbatch
rather than working in an interactive job). A resulting issue is that, for example, print()
statements don’t appear in your job’s slurm.out
file (see Monitoring a job) until the
buffer is flushed.
This issue can be resolved by applying one of the following strategies:
Note
The final two options will run both output streams, stdout
and stderr
, unbuffered.
- change the
print
functions inside your Python script:
Replaceprint("your text here")
withprint("your text here", flush=True)
- change the
python
command in your job script:
Replacepython your_script.py
withpython -u your_script.py
, i.e. adding-u
to tell Python to run unbuffered - set the
PYTHONUNBUFFERED
environment variable by addingexport PYTHONUNBUFFERED=1
to the script before thepython
command is run