[C++-sig] Boost Python in dynamic libraries

Slide slide.o.mix at gmail.com
Wed Nov 25 11:01:28 EST 2015


Wow, that was great! I appreciate your help. I indeed was not calling
Py_Initialize before loading the libraries. Much appreciated!

On Wed, Nov 25, 2015 at 7:40 AM Giuseppe Corbelli <
giuseppe.corbelli at copangroup.com> wrote:

> On 25/11/2015 00:30, Slide wrote:
> > I have a set of plugins that I am loading from shared libraries on
> Linux. I
> > thought I would want to call the initModule function when loading the
> library,
> > but I am getting the following error when I do so:
> >
> > Fatal Python error: PyThreadState_Get: no current thread
> > Aborted (core dumped)
> >
> > Can anyone point me to an example of something like this? I am using
> > BOOST_PYTHON_MODULE in my shared libraries and then loading them at
> runtime. I
> > would like to import that module into my main namespace where most of my
> code
> > is being run.
>
> If you have a look at the interpreter code (assuming 2.7 series), you'll
> see that
>
> PyThreadState *
> PyThreadState_Get(void)
> {
>      if (_PyThreadState_Current == NULL)
>          Py_FatalError("PyThreadState_Get: no current thread");
>
>      return _PyThreadState_Current;
> }
>
> PyThreadState *_PyThreadState_Current is defined in Python/pystate.c and
> initialized as NULL.
>
> In Python/pythonrun.c within Py_InitializeEx() call a new thread state is
> initialized and PyThreadState_Swap() sets it.
>
> In short: I'd say you didn't call Py_Initialize() before dlopen()ing the
> shared objects.
>
> --
>              Giuseppe Corbelli
> WASP Software Engineer, Copan Italia S.p.A
> Phone: +390303666318  Fax: +390302659932
> E-mail: giuseppe.corbelli at copangroup.com
> _______________________________________________
> Cplusplus-sig mailing list
> Cplusplus-sig at python.org
> https://mail.python.org/mailman/listinfo/cplusplus-sig
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/cplusplus-sig/attachments/20151125/de0e9748/attachment.html>


More information about the Cplusplus-sig mailing list