Unbuffered stderr in Python 3
srinivas devaki
mr.eightnoteight at gmail.com
Fri Nov 6 08:40:07 EST 2015
On Mon, Nov 2, 2015 at 1:22 PM, Steven D'Aprano
<steve+comp.lang.python at pearwood.info> wrote:
>
> So how come Python 3 has line buffered stderr? And more importantly, how can
> I turn buffering off?
>
> I don't want to use the -u unbuffered command line switch, because that
> effects stdout as well. I'm happy for stdout to remain buffered.
>
you can simply turn buffering off for stderr by redefining the print
function or declaring a new print function like
from functools import partial
print = partial(print, flush=True)
# or
from functools import partial
import sys
printerr = partial(print, flush=True, file=sys.stderr)
More information about the Python-list
mailing list