jupyter / notebook

Jupyter Interactive Notebook
https://jupyter-notebook.readthedocs.io/
BSD 3-Clause "New" or "Revised" License
11.52k stars 4.82k forks source link

Error: "basic_string::_M_construct null not valid", when using Boost-Python-compiled C++ library #2678

Open mikehamer opened 7 years ago

mikehamer commented 7 years ago

I have written some algorithms in C++ for performance reasons. Using boost_python I have successfully wrapped these into a Python library, and wish to import and call these functions.

This works perfectly in Python:

# ls
test.py  Test.so

# cat test.py
from Test import TestClass
T = TestClass()
print(T.TestFunc())

# python test.py
(6, 7, 2)

This works when using jupyter console (and jupyter qtconsole, and ipython)

# jupyter console                                                                                                                                                                            
Jupyter console 5.1.0

Python 3.6.0 |Anaconda custom (64-bit)| (default, Dec 23 2016, 12:22:00)
Type 'copyright', 'credits' or 'license' for more information
IPython 6.1.0 -- An enhanced Interactive Python. Type '?' for help.

In [1]: !cat test.py
from Test import TestClass
T = TestClass()
print(T.TestFunc())

In [2]: %run test.py
(6, 7, 2)

But when using Jupyter Notebooks:

!cat test.py
%run test.py

from Test import TestClass
T = TestClass()
print(T.TestFunc())
---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
~/Notebooks/test.py in <module>()
      1 from Test import TestClass
----> 2 T = TestClass()
      3 print(T.TestFunc())

RuntimeError: basic_string::_M_construct null not valid

I am running the master branch of jupyter notebook, and have additionally upgraded jupyter hub and ipython.

jupyter notebook --version
5.1.0.dev

This does not seem to be a general problem with boost-python. I have tried to create a minimal breaking example, but have failed. The trivial boost-python libraries that I have tried have worked as expected.

I assume, therefore, that there is some issue with the interplay between my library and jupyter notebook. Since this issue doesn't present itself when using python, I am unable to debug using gdb on the python process, and the ipython %%debug magic doesn't step into the C++ library.

Since the library has significant local dependencies, it is not trivial for me to make available. I am therefore hoping that you might be able to give me some insight into how I might debug this issue.

takluyver commented 7 years ago

Nothing comes to mind - there should be no meaningful differences in the environment code runs in between different Jupyter frontends (notebook, qtconsole, console).