[C++-sig] Boost python exception translation failure on BlueGene/P

James Amundson amundson at fnal.gov
Fri Feb 19 05:28:17 CET 2010


On 02/18/2010 05:19 PM, Ralf W. Grosse-Kunstleve wrote:
> Your problem may be that an exception thrown in one .so isn't correctly caught in another .so.
>    
Hmmm. I only have one module in my test -- pyexcept. Is the fact that it 
has to link to libboost_python enough to cause that problem?
> In the dark past we had problems like this, too. To this day I don't import extensions
> directly, but use a small wrapper function, import_ext(). The essential bit is
>
>      sys.setdlopenflags(0x100|0x2)
>
> The hex values are platform specific. IIRC it is RTLD_NOW | RTLD_GLOBAL (may be backwards).
> You want to insert something like this right before importing your extension.
>    
OK. I tried this:
---------------------------------------------------------------------------------
#!/usr/bin/env python
import sys
import dl
sys.setdlopenflags(dl.RTLD_NOW | dl.RTLD_GLOBAL)
import pyexcept

print "about to run pyexcept.foo, catching exception"
try:
     pyexcept.foo()
except RuntimeError,e:
     print "caught RuntimeError,",e

---------------------------------------------------------------------------------

I saw the same behaviour as before -- I never catch the exception.

Thanks for the suggestion, though. It was new to me.

--Jim Amundson


More information about the Cplusplus-sig mailing list