[SciPy-User] capturing stdout, stderr from integrate.odeint() ?

Nathaniel Smith njs@pobox....
Tue Jan 15 10:51:32 CST 2013

On 15 Jan 2013 14:22, "RKBelew" <rik@cogsci.ucsd.edu> wrote:
> i'm trying to capture the various warnings being generated
> by lsoda from the FORTRAN library odepack, ala
> > lsoda--  warning..internal t (=r1) and h (=r2) are
> >        such that in the machine, t + h = t on the next step
> >        (h = step size). solver will continue anyway
> >       In above,  R1 =  0.2867368005697E+02   R2 =  0.1738483517440E-14
> my strategy has been to just redirect sys.stdout and/or sys.stderr
> to a StringIO() buffer and then explore it.  but that isn't working:
> i still get the warnings, and my buffer remains empty?
> can someone point me to where in the guts of scipy.integrate
> this might be resolved, and/or why my approach isn't working?

sys.std{out,err} are ordinary Python file objects, which normally
point to the operating system stdout/stderr (file descriptors 1 and
2). The fortran code is writing directly to the operating system
stdout/stderr without going through the Python layer, so redirecting
things at the Python layer doesn't help.

It's possible to work around this using elaborate Unix tricks --
create an os.pipe(), use os.dup2() to set it up so that writes to file
descriptors 1 and 2 will go to your pipe, create some threads to read
the other ends of the pipes into a Python buffer of some sort -- but
it may not be worth the hassle. The other cumbersome workaround would
be to split your odepack-using code out into a separate program, and
then use the 'subprocess' module to call it and read its output...


More information about the SciPy-User mailing list