How do I save print statements when running a program in SLURM?

By default, print in Python is buffered, meaning that it does not write to files or stdout immediately, and needs to be ‘flushed’ to force the writing to stdout immediately.

See this question for available options.

The simplest option is to start the Python interpreter with the -u option.

From the python man page:

-u Force stdin, stdout and stderr to be totally unbuffered. On systems where it matters, also put stdin, stdout and stderr in binary mode.
Note that there is internal buffering in xreadlines(), readlines() and
file-object iterators (“for line in sys.stdin”) which is not
influenced by this option. To work around this, you will want to use
“sys.stdin.readline()” inside a “while 1:” loop.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)