pearu / f2py

Automatically exported from code.google.com/p/f2py
Other
54 stars 37 forks source link

Support redirection of stdout / stderr into CPython descriptors #31

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. Wrap some code that contains WRITE statements with f2py
2. Try to capture this output on Python stdout / stderr descriptors
3. Watch yourself fail

What is the expected output? What do you see instead?

I would expect to be able to capture the text printed by wrapped routines from 
inside Python.

What version of the product are you using? On what operating system?

Latest NumPy / SciPy / f2py / Python 2.7 / Linux + Windows

Please provide any additional information below.

See e.g. http://projects.scipy.org/scipy/ticket/1350 for discussion:

In essence, SciPy wraps a lot around Fortran code, e.g. for optimizers. 
Unfortunately, these codes print a lot of interesting debugging (not only 
debugging, actually) information on stdout / stderr and this output can not be 
captured / parsed automatically from within Python.

It is possible to modify the wrappers to return more information, but it is 
tedious and not practical to change every function that uses WRITE so that it 
adds text to a global string that will be returned to Python.

The solution that I have in mind is to implement an extra function from within 
f2py, e.g. WRITE_PYTHON which would be identical to WRITE, but actually use 
PySys_WriteStdout to write to the same descriptors that Python has opened.

Probably this will also require the modification of the Fortran codes, but mass 
replacement of WRITE with WRITE_PYTHON already looks much more reasonable.

Discussion and alternative solutions are welcome!

Thanks!

Original issue reported on code.google.com by yury.v.zaytsev on 3 Jan 2011 at 3:04

GoogleCodeExporter commented 8 years ago
The references issue has moved: https://github.com/scipy/scipy/issues/1875

Original comment by yury.v.zaytsev on 26 Apr 2013 at 6:42