capture stdout/stderr output from cython/c modules

2,169 views
Skip to first unread message

PeterC

unread,
Mar 7, 2016, 2:09:41 PM3/7/16
to Project Jupyter
print() statements in python *.py and cython *.pyx modules appear in the Jupyter nb but printf() statements from extern c functions in a cython module appear in the console that launched the Jupyter session.

I have some cython modules with external c functions which printf() and fprintf() info to stdout and stderr. Is it possible to get them to print to the Jupyter notebook like regular python and cython print() statements and if so then how?

Many thanks, Peter

Matthias Bussonnier

unread,
Mar 7, 2016, 2:38:18 PM3/7/16
to jup...@googlegroups.com
Hello Peter,

Unfortunately the python redirection is done by monkey patching
sys.stdout/err. It is not easy (maybe likely not possible) to redirect
things that get called from c or cython.
as they access filedescriptors directly.

You can take a look at things like:

http://stackoverflow.com/questions/5081657/how-do-i-prevent-a-c-shared-library-to-print-on-stdout-in-python

Which gives some hacks with file descriptors. Though messing with
filedescriptors like this will probably give unexpected results.

--
M
> --
> You received this message because you are subscribed to the Google Groups
> "Project Jupyter" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to jupyter+u...@googlegroups.com.
> To post to this group, send email to jup...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/jupyter/4c5fe965-bfc6-4199-9858-c1e1b3ea70ef%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages