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 from C++ library not shown on IPython console #9759

Closed
10 tasks done
gtarabat opened this issue Jul 5, 2019 · 8 comments
Closed
10 tasks done

Output from C++ library not shown on IPython console #9759

gtarabat opened this issue Jul 5, 2019 · 8 comments

Comments

@gtarabat
Copy link

gtarabat commented Jul 5, 2019

Issue Report Checklist

  • Searched the issues page for similar reports
  • Read the relevant sections of the Spyder Troubleshooting Guide and followed its advice
  • Reproduced the issue after updating with conda update Spyder (or pip, if not using Anaconda)
  • Could not reproduce inside jupyter qtconsole (if console-related)
  • Tried basic troubleshooting (if a bug/error)
    • Restarted Spyder
    • Reset preferences with Spyder --reset
    • Reinstalled the latest version of Anaconda
    • Tried the other applicable steps from the Troubleshooting Guide
  • Completed the Problem Description, Steps to Reproduce and Version sections below

Problem Description

I create a Python binding of a C++ code using the library pybind11. The C++ code has a single function that receives an integer N and prints all the integers less than N, one on each line. I run the python part inside Spyder.

When N is small, e.g. N=100, the expected output is obtained. When N is large, e.g. N=100000, no output is obtained and the script hangs.

The problem does not appear if I run from IPython or from terminal or from a jupyter notebook. The same problem appears with pip and conda.

What steps reproduce the problem?

  1. conda install pybind11

  2. Open a file with name printx.cpp and paste the following code:

#include <iostream>
#include <pybind11/pybind11.h>

void printloop(int N){
  for(int i=0; i<N; i++)
    printf("%d\n",i);
}

PYBIND11_MODULE(printx, m) {
    m.doc() = "Minimal working example to reproduce a bug in Spyder using pybind11.";
    m.def("printloop", &printloop, "Print integers in a loop.");
}
  1. Compile the library:
c++ -O3 -Wall -shared -std=c++11 -undefined dynamic_lookup `python3 -m pybind11 --includes` printx.cpp -o printx`python3-config --extension-suffix`
  1. Run the following from Spyder:
import printx as x
x.printloop(100000);

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

The expected output is 100000 integers printed on the screen, one on each line. Instead, nothing is printed on screen and the python script hangs.

Versions

  • Spyder version: 3.3.3
  • Python version: 3.7.3
  • Qt version: 5.9.7
  • PyQt version: 5.9.2
  • Operating System name/version: macOS Mojave (10.14.5)

Dependencies

IPython >=4.0     :  7.4.0 (OK)
cython >=0.21     :  0.29.6 (OK)
jedi >=0.9.0      :  0.13.3 (OK)
matplotlib >=2.0.0:  3.0.3 (OK)
nbconvert >=4.0   :  5.4.1 (OK)
numpy >=1.7       :  1.16.2 (OK)
pandas >=0.13.1   :  0.24.2 (OK)
psutil >=0.3      :  5.6.1 (OK)
pycodestyle >=2.3 :  2.5.0 (OK)
pyflakes >=0.6.0  :  2.1.1 (OK)
pygments >=2.0    :  2.3.1 (OK)
pylint >=0.25     :  2.3.1 (OK)
qtconsole >=4.2.0 :  4.4.3 (OK)
rope >=0.9.4      :  0.12.0 (OK)
sphinx >=0.6.6    :  1.8.5 (OK)
sympy >=0.7.3     :  1.3 (OK)
@ccordoba12
Copy link
Member

This is fixed in our latest version. Please update by opening Terminal.app and running there

conda install spyder=3.3.5

@gtarabat
Copy link
Author

gtarabat commented Jul 8, 2019

I updated to spyder=3.3.5 but the problem remains.

@ccordoba12 ccordoba12 reopened this Jul 8, 2019
@ccordoba12 ccordoba12 changed the title Lengthy output from C++ library not shown on Spyder IPython console Output from C++ library not shown on Spyder IPython console Jul 8, 2019
@ccordoba12 ccordoba12 changed the title Output from C++ library not shown on Spyder IPython console Output from C++ library not shown on IPython console Jul 8, 2019
@ccordoba12 ccordoba12 added this to the important milestone Jul 8, 2019
@ccordoba12
Copy link
Member

ccordoba12 commented Jul 8, 2019

Could you use std::out instead of printfto see if that makes a difference? Thanks!

@gtarabat
Copy link
Author

gtarabat commented Jul 8, 2019

Thank you Carlos. Using std::cout has the same behavior as with printf.

@groussea
Copy link

I get a similar problem although the outputs are visible at the end of the C++ run in my case.
However, it would be nice to show the outputs in spyder-kernel when code is running as it works with iPython in an external system terminal.

@moorepants
Copy link

We are having a possibly related issue here: mechmotum/cyipopt#88 FYI

@ccordoba12 ccordoba12 modified the milestones: v5.0alpha4, v5.0alpha5 Feb 14, 2021
@ccordoba12 ccordoba12 modified the milestones: v5.0alpha5, v5.0alpha6 Feb 23, 2021
@ricewenzhou
Copy link

I make a .pyd with pybind11. The std::cout works fine in Ipython when it is called from the pwsh, but it does not work in spyder. ipython 7.4. spyder 4.2.3.

@ccordoba12
Copy link
Member

There's already a pull request to solve this, we'll try to merge it in the next weeks.

@ccordoba12 ccordoba12 modified the milestones: v5.0alpha6, v5.0beta1 Mar 19, 2021
@ccordoba12 ccordoba12 modified the milestones: v5.0.0, v5.x Apr 2, 2021
@ccordoba12 ccordoba12 modified the milestones: v5.x, v5.2.0 Nov 17, 2021
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

6 participants