On Apr 4, 2009, at 10:22 AM, Nick Rothwell wrote:
> I have a package which embeds Jython into MaxMSP (http://www.cycling74.com/products/max5
> ). Max has a message logging window, and the embedded Java-in-Max
> redirects standard output and error to this window.
> This all works fine with Jython 2.2.1, but I'm not seeing anything
> with 2.5b3. Well, I'm seeing the "processing new jar" messages (to
> standard error?) but nothing from Python's "print".
> Ah, a clue: lines output with
I'm not sure what you mean here, this looks like a Python 3 style
print function. Do you mean the normal print statement? i.e. print 'foo'
> don't appear until I do a
> from java.lang import System
> when everything gets flushed out (complete with line terminators).
stdout is now lined buffered, like in CPython, whereas it wasn't in
2.2. You can disable this buffering via a command line option or with
a Java property when initializing Jython. However note that this also
opens stdout/err/in into binary mode.
You could also disable buffering at runtime by reopening the
underlying file descriptor:
sys.stdout = os.fdopen(sys.stdout.fileno(), sys.stdout.mode, 0) # 0