Skip to content

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:
    Replace print("your text here") with print("your text here", flush=True)
  • change the python command in your job script:
    Replace python your_script.py with python -u your_script.py, i.e. adding -u to tell Python to run unbuffered
  • set the PYTHONUNBUFFERED environment variable by adding export PYTHONUNBUFFERED=1 to the script before the python command is run