unbuffering std streams in code
Fredrik Lundh
fredrik at pythonware.com
Sat May 28 10:23:56 EDT 2005
John Reese wrote:
> You know how you can specify that stderr, stdin, stdout should be
> unbuffered by running python with the -u switch? Is there any way I
> can have the same affect in code by doing something to the sys.std*
> variables?
try this:
>>> import os, sys
>>> sys.stdout = os.fdopen(sys.stdout.fileno(), sys.stdout.mode, 0)
(repeat for the other streams)
(-u does a bit more than this on some platforms, but the above
should be good enough for many purposes)
</F>
More information about the Python-list
mailing list