Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Output of C extensions is not shown in IPython console #3777

Closed
peendebak opened this issue Dec 2, 2016 · 19 comments
Closed

Output of C extensions is not shown in IPython console #3777

peendebak opened this issue Dec 2, 2016 · 19 comments

Comments

@peendebak
Copy link

Description of your problem

The output of C extensions that print to stdout is not shown in the ipython console. For Spyder 2 the output was shown in the kernel window.

A minimal example:

import oapackage
T=oapackage.conference_transformation_t()
T.show()

When executed from the command line a message is shown, in the Spyder 3 ipython console no output is shown at all.

Note: oapackage can by installed from pypi: https://pypi.python.org/pypi/OApackage. The output desired is generated by C++ code wrapped using SWIG.

Note: the same problem is there when the code is executed in an ipython notebook.

@ccordoba12
Copy link
Member

@minrk or @takluyver, is there a configuration setting we can change in qtconsole to redirect stdout/stderr of all C extensions to the zmq corresponding channel?

@ccordoba12 ccordoba12 changed the title output of c extensions in ipython console Output of C extensions is not shown in IPython console Dec 2, 2016
@takluyver
Copy link
Contributor

There isn't a config setting, but you can use Min's package wurlitzer in the kernel.

Once we implement the kernel nanny proposal, we'll be able to capture this kind of output automatically.

@ccordoba12
Copy link
Member

Thanks a lot Thomas! We'll use wurlitzer in the meantime :-)

Once we implement the kernel nanny proposal ...

This seems more and more important for Spyder. What are your plans about it? Do you have a time frame for it?

I say it because we have now 4 new junior developers working for Spyder, so I could assign some of them to work on this project (under your guidance and my supervision, of course :-).

@takluyver
Copy link
Contributor

We discussed it again at the dev meeting, but there isn't an explicit time frame. The primary sticking point for me is that we still don't have a firm decision on whether we use one nanny process for one kernel, or one nanny process per system, managing multiple kernels.

@ccordoba12
Copy link
Member

Ok, thanks. Please let me know if you need some help with that :-)

@peendebak
Copy link
Author

Another example that does not generate output in the spyder3 with the ipython console

import os
os.system('ls')

@YWaller
Copy link

YWaller commented Mar 23, 2018

Any update on this issue? I'd like to get tensorflow logs in my console...

@nyngwang
Copy link

I need this feature, please?

@ccordoba12 ccordoba12 modified the milestones: v4.0betaX, v3.3.1 May 19, 2018
@ccordoba12
Copy link
Member

Sorry, we haven't worked on this one yet. We could work on it after we release 3.3 though.

@jitseniesen
Copy link
Member

I had a quick try. It is easy to change spyder-kernels to load the wurlitzer extension on startup and this does the job:

wurlitzer

Normally, the output "bla" of the echo command is lost. There is a slight difference with running python from the console, in that IPython run from Spyder forwards the output through Python's sys.stdout while when running python from the console, the output is interspersed with python's output without going through sys.stdout (if I understand it correctly). Nevertheless, I think this is an improvement to the current situation.

@ccordoba12 How to proceed?

  1. We can add wurlitzer as a dependency to spyder-kernels. This is perhaps not so nice for a minor release. Additionally, wurlitzer is not available in the default conda channel, only in conda-forge and pip.
  2. We can include the source code of wurlitzer in spyder-kernels. It is just one file and MIT licensed. The main disadvantage is that we would not profit from any improvements in the wurlitzer package.
  3. As a middle way, we could do option 2 for spyder 3.x and spyder-kernels 0.x and option 1 for spyder 4.x and spyder-kernels 1.x.

@ccordoba12
Copy link
Member

ccordoba12 commented Aug 10, 2018

We can add wurlitzer as a dependency to spyder-kernels.

This is the option I was planning to implement in a couple of weeks.

This is perhaps not so nice for a minor release

We can add this minor improvement to spyder-kernels 0.3. After that, I don't plan to add more enhancements to that branch.

Additionally, wurlitzer is not available in the default conda channel, only in conda-forge and pip.

I know wurlitzer is not part of Anaconda, but since it's already part of conda-forge, the Anaconda guys can add it without problems.

@ccordoba12
Copy link
Member

ccordoba12 commented Aug 10, 2018

I said minor in the sense that it doesn't require too much work and it's not too disruptive. I know it's very important to work with certain libraries.

@jitseniesen
Copy link
Member

I guess this should be moved to the spyder-kernels repository?

@ccordoba12
Copy link
Member

We can close this issue with a PR from spyder-kernels, so let's not move it because it has all our discussion about this topic.

@ccordoba12
Copy link
Member

This will be fixed once we release spyder-kernels 0.3.0, in a couple of weeks.

@Nicholaswogan
Copy link

Is it possible to turn off the C printing to the IPython console? I'd rather just see the C extension stuff in my terminal, which has the jupyter notebook opened.

@ccordoba12
Copy link
Member

Sorry, now you can't opt-out of this behavior.

@minrk
Copy link
Contributor

minrk commented Apr 20, 2022

It can't be toggled at runtime (except with some private API calls), but you can disable it globally:

# ipython_config.py
c.IPKernelApp.capture_fd_output = False

@Nicholaswogan
Copy link

It works great! Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

8 participants