unbuffering std streams in code

Discussion in 'Python' started by John Reese, May 28, 2005.

  1. John Reese

    John Reese Guest

    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?
     
    John Reese, May 28, 2005
    #1
    1. Advertising

  2. 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>
     
    Fredrik Lundh, May 28, 2005
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.

Share This Page