From: Samuele P. <ped...@bl...> - 2004-03-05 00:56:07
|
At 15:37 26.02.2004 -0700, Jonathan Ellis wrote: >Re: >http://sourceforge.net/tracker/index.php?func=detail&aid=674932&group_id >=12867&atid=112867 > >There's a couple problems with the code involved here. First, Py.print >is wrapping the file target in a new FixedFileWrapper with _each_ call >to print. Second, StdoutWrapper, the base class of FFW, flushes after >each write as Samuele suspected. > >Proposed Solution: > - The main fix is that StdoutWrapper should inherit from a base class. >The base class will never call flush(), but Stdout will continue to do >so. > - We should probably also rename these *Wrapper classes to >*PrintHelper classes, because PyFile uses FileWrapper classes to mean >something different. So there will be the base PrintHelper class, >StdoutPrintHelper, and StderrPrintHelper. There will no longer be an >analogue of the FixedFileWrapper class; its functionality will be >handled by PrintHelper in a more generic manner. > - PrintHelper will have static helper methods to avoid code >duplication, e.g. instead of > > public static void print(PyObject file, PyObject o) { > if (file == None) > print(o); > else > new FixedFileWrapper(file).print(o); > } > > it will read > > public static void print(PyObject file, PyObject o) { > file = PrintHelper.getPrinter(file); > file.print(o); > } > > - getPrinter will allow us to cache PrintHelper objects so that a loop >that does 1000 prints to a file won't create 1000 PrintHelper wrappers. >Caching will use WeakHashMap so GC behavior will be unchanged. yes, a patch along these lines would make much sense. Thanks for looking into this. |