473,320 Members | 1,863 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

How do I control output buffering on Win32?

When I ssh in to my Windows XP box and run Python apps, output
from "print" and and "sys.stdout.write()" is being buffered so
that none of the output shows up until the program exits.

From within my program how do I set output buffering to either
line-buffered or un-buffered? [I'm looking for the equivalent
of the C stdio "setbuf" call.]

--
Grant Edwards grante Yow! I'm rated PG-34!!
at
visi.com
Aug 15 '08 #1
4 1580
Grant Edwards wrote:
When I ssh in to my Windows XP box and run Python apps, output
from "print" and and "sys.stdout.write()" is being buffered so
that none of the output shows up until the program exits.
>>From within my program how do I set output buffering to either
line-buffered or un-buffered? [I'm looking for the equivalent
of the C stdio "setbuf" call.]
I'm not sure you can do that from within the program [1]; to do it from
the outside, set the PYTHONUNBUFFERED environment variable to something,
or pass "-u" to the interpreter.

</F>

1) well, I suppose you could replace sys.stdout with a thin wrapper that
does flush after each write, or play with os.fdopen.

Aug 15 '08 #2
On 2008-08-15, Fredrik Lundh <fr*****@pythonware.comwrote:
Grant Edwards wrote:
>When I ssh in to my Windows XP box and run Python apps, output
from "print" and and "sys.stdout.write()" is being buffered so
that none of the output shows up until the program exits.
>>>From within my program how do I set output buffering to either
line-buffered or un-buffered? [I'm looking for the equivalent
of the C stdio "setbuf" call.]

I'm not sure you can do that from within the program [1]; to
do it from the outside, set the PYTHONUNBUFFERED environment
variable to something, or pass "-u" to the interpreter.
I had seen references to PYTHONUNBUFFERED in my Google search,
but it wasn't mentioned when I did a "python -h" -- so I
assumed it was a Unix-only thing.
1) well, I suppose you could replace sys.stdout with a thin
wrapper that does flush after each write, or play with
os.fdopen.
I thought about that, but it seemed like there ought to be an
easier, more obvious way.

Is there some technical reason a Python program can't control
the output buffering the way a C program can with setvbuf()? Or
is it just something that's only wanted by weird people who do
things like ssh into Windows boxes?

That raises another question: what is the criteria that Python
is using when it decides to run my program in block-buffered
mode instead of line- or un-buffered mode?

--
Grant Edwards grante Yow! I've read SEVEN
at MILLION books!!
visi.com
Aug 15 '08 #3
On 2008-08-15, Grant Edwards <gr****@visi.comwrote:
>I'm not sure you can do that from within the program [1]; to
do it from the outside, set the PYTHONUNBUFFERED environment
variable to something, or pass "-u" to the interpreter.

I had seen references to PYTHONUNBUFFERED in my Google search,
but it wasn't mentioned when I did a "python -h"
assumed it was a Unix-only thing.
Doh. Yes it was. I don't know how I missed it...

--
Grant Edwards grante Yow! Uh-oh!! I forgot
at to submit to COMPULSORY
visi.com URINALYSIS!
Aug 15 '08 #4
On Fri, 15 Aug 2008 09:47:34 -0500, Grant Edwards wrote:
When I ssh in to my Windows XP box and run Python apps, output
from "print" and and "sys.stdout.write()" is being buffered so
that none of the output shows up until the program exits.

From within my program how do I set output buffering to either
line-buffered or un-buffered? [I'm looking for the equivalent
of the C stdio "setbuf" call.]
That's not exactly what you want, but what about creating your
own printing function and flushing at its end?

import sys
def printf(mystr):
print mystr
sys.stdout.flush()

--
Regards,
Wojtek Walczak,
http://www.stud.umk.pl/~wojtekwa/
Aug 15 '08 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: vishal | last post by:
hi vishal here. can anyone tell me that how to buffer output and then send the output to client at a time. what is my problem is that i have a php file which runs query on database and takes...
2
by: Patrick L. Nolan | last post by:
I'm going nuts trying to port an application from Linux to Windows. We have a python/Tkinter script which runs a C++ application. It starts it with popen4 and communicates through the two pipes....
1
by: Tim Mohler | last post by:
All - I have a script that provides a web page interface to various system utilities. Once the user has selected the utility and input various parameters, it calls itself with a different method...
5
by: Alien | last post by:
I have a hex editor-type class that extends UserControl and paints its data to a PictureBox. Basically the problem is that repainting it takes usually between 60 and 80ms, which may seem pretty...
2
by: hzgt9b | last post by:
Using VS2003, VB.NET, BACKGROUND I have a window forms based application that will be distributed and executed directly from CD media. The app contains a TreeView control and a WebBroswer...
4
by: Pawel Halastra FrT | last post by:
Elo, I'm having a terrible trouble with a simple, as I think, issue. I need to stop my script in the middle of proccesing, and, simultanously, start a new script. The idea is not to sent any...
15
by: jools | last post by:
I'm having trouble modifying some code written by someone else. The code is very dense and obscure but does work fine. However I need to insert a block of my own and I've hit what I assume is a...
25
by: Abubakar | last post by:
Hi, recently some C programmer told me that using fwrite/fopen functions are not efficient because the output that they do to the file is actually buffered and gets late in writing. Is that...
5
by: thedsadude | last post by:
Hello, I'm launching a script as follows: <code> p = subprocess.Popen() p.wait() </code> If p.py writes to sys.stdout, then it is shown on the console.
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.