Decorators and buffer flushing

Ethan Metsger me at metsger.com
Mon Mar 3 12:06:28 EST 2008


Hi, Gabriel.  I missed this message initially; I apologize for not  
responding sooner.

On Thu, 28 Feb 2008 18:53:28 -0500, Gabriel Genellina  
<gagsl-py2 at yahoo.com.ar> wrote:

>> I can reproduce the issue in the console.  I'm not convinced it's  
>> actually
>> a bug, unless for some reason the interpreter is preventing a buffer  
>> flush.
>
> Try starting the interpreter with python -u xxx.py (-u = unbuffered) but  
> I don't really think this might be the cause. Are you sure the code  
> actually says sys.stdout.flush() and not sys.stdout.flush?

As I mentioned in another message, I haven't had any luck with adding '-u'  
to the invocation of the interpreter.  I am sure I'm not looking at the  
callable object rather than calling flush().

>>        sys.stdout.write ("%s" % (self.name.ljust(30),))
>
> Usually written as:
> sys.stdout.write("%-30s" % self.name)

Thanks for the tips!

[...]

>> Is it possible that flushing is prohibited until __exit__ is called?
>
> I don't think so... What's your platform/OS?

I'm running Ubuntu Feisty with Python 2.5.1:

Python 2.5.1 (r251:54863, May  2 2007, 16:56:35)
[GCC 4.1.2 (Ubuntu 4.1.2-0ubuntu4)] on linux2

> Try to post a minimal example showing the problem - copy & paste it,  
> don't retype. Maybe in the process of reducing your code to find the  
> minimal example, you find the problem yourself.

The minimal example is a little long, but I think in the end I figured out  
what was happening.  The initial build step took the longest amount of  
time to complete, but the other steps were nearly instantaneous.

So the post-build '.' would appear, and the very fast run of the other  
steps made it appear as though everything was being buffered when it  
wasn't.  Adding in a short delay (time.sleep(0.05) seemed to work) helped  
demonstrate that the data actually were unbuffered.

> Are you aware of the existing framework for unit tests? the unittest  
> module?

Yes.  I haven't investigated its uses in this context due to the  
constraints of the legacy system and general inertia.  I'm trying to  
duplicate functionality while addressing certain annoyances with the  
previous system.


Thanks again for your help!

Best,

Ethan

-- 
Ethan Metsger
http://uppertank.net/ethanm/



More information about the Python-list mailing list