[prev in list] [next in list] [prev in thread] [next in thread] 

List:       python-cpp-sig
Subject:    Re: [C++-sig] Boost Python in dynamic libraries
From:       Slide <slide.o.mix () gmail ! com>
Date:       2015-11-25 16:01:28
Message-ID: CAPiUgVf3ZBtoyVunyEHyH4oEnJGuc3CgLdSh6wwBTh8H7qTXdA () mail ! gmail ! com
[Download RAW message or body]

[Attachment #2 (multipart/alternative)]


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@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@copangroup.com
> _______________________________________________
> Cplusplus-sig mailing list
> Cplusplus-sig@python.org
> https://mail.python.org/mailman/listinfo/cplusplus-sig
>

[Attachment #5 (text/html)]

<div dir="ltr">Wow, that was great! I appreciate your help. I indeed was not calling \
Py_Initialize before loading the libraries. Much appreciated!</div><br><div \
class="gmail_quote"><div dir="ltr">On Wed, Nov 25, 2015 at 7:40 AM Giuseppe Corbelli \
&lt;<a href="mailto:giuseppe.corbelli@copangroup.com">giuseppe.corbelli@copangroup.com</a>&gt; \
wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 \
.8ex;border-left:1px #ccc solid;padding-left:1ex">On 25/11/2015 00:30, Slide \
wrote:<br> &gt; I have a set of plugins that I am loading from shared libraries on \
Linux. I<br> &gt; thought I would want to call the initModule function when loading \
the library,<br> &gt; but I am getting the following error when I do so:<br>
&gt;<br>
&gt; Fatal Python error: PyThreadState_Get: no current thread<br>
&gt; Aborted (core dumped)<br>
&gt;<br>
&gt; Can anyone point me to an example of something like this? I am using<br>
&gt; BOOST_PYTHON_MODULE in my shared libraries and then loading them at runtime. \
I<br> &gt; would like to import that module into my main namespace where most of my \
code<br> &gt; is being run.<br>
<br>
If you have a look at the interpreter code (assuming 2.7 series), you&#39;ll see \
that<br> <br>
PyThreadState *<br>
PyThreadState_Get(void)<br>
{<br>
        if (_PyThreadState_Current == NULL)<br>
              Py_FatalError(&quot;PyThreadState_Get: no current thread&quot;);<br>
<br>
        return _PyThreadState_Current;<br>
}<br>
<br>
PyThreadState *_PyThreadState_Current is defined in Python/pystate.c and<br>
initialized as NULL.<br>
<br>
In Python/pythonrun.c within Py_InitializeEx() call a new thread state is<br>
initialized and PyThreadState_Swap() sets it.<br>
<br>
In short: I&#39;d say you didn&#39;t call Py_Initialize() before dlopen()ing the<br>
shared objects.<br>
<br>
--<br>
                    Giuseppe Corbelli<br>
WASP Software Engineer, Copan Italia S.p.A<br>
Phone: +390303666318   Fax: +390302659932<br>
E-mail: <a href="mailto:giuseppe.corbelli@copangroup.com" \
target="_blank">giuseppe.corbelli@copangroup.com</a><br> \
_______________________________________________<br> Cplusplus-sig mailing list<br>
<a href="mailto:Cplusplus-sig@python.org" \
target="_blank">Cplusplus-sig@python.org</a><br> <a \
href="https://mail.python.org/mailman/listinfo/cplusplus-sig" rel="noreferrer" \
target="_blank">https://mail.python.org/mailman/listinfo/cplusplus-sig</a><br> \
</blockquote></div>



_______________________________________________
Cplusplus-sig mailing list
Cplusplus-sig@python.org
https://mail.python.org/mailman/listinfo/cplusplus-sig

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic