!! Non blocking IO !!

greg andruk meowing at banet.net
Thu Sep 30 08:53:52 EDT 1999


In nnmh:python, Pierre Saloni <me at nospam.com> wrote:

>     Yes it is right ... sorry, i meant $|=1 ...
>     In fact what I want is an autoflush when I print, i do not want print to
> bufferize at all.
>     I did this in perl, but cannot find the right way in python.

Hmm.  Does this trick work only on U*X?

import sys, os, time

def tryit():
    print "part 1",
    time.sleep(3)
    print "part 2"

print "On the console, this should sleep before displaying both parts..."
tryit()

# Reattach sys.stdout to an unbuffered file object.
newout = os.fdopen(sys.stdout.fileno(), 'w', 0)
sys.stdout = newout

print "This time the first part should before the pause."
tryit()




More information about the Python-list mailing list