Boost logo

Boost :

Subject: Re: [boost] Boost.Python sandox or multiple interpreters
From: Stefan Seefeld (stefan_at_[hidden])
Date: 2017-01-13 12:05:38


On 13.01.2017 11:40, David Bellot wrote:
> Hi,
>
> I'm using Boost.Python to load and use plugins in Python. Each plugin can
> define a few functions which are are pre-determined, so that my C++
> software knows what to call.
>
> However, the mistake I've made was to think that the Python interpreter
> could be initialized many times, so that each plugins was existing and
> running into a separate interpreter. It's of course not the case and
> therefore, each time I load a new plugin, its functions overwrite the
> functions of the same name from the previous plugin (the one which was
> loaded just before), and so on.
>
> Is there a possibility to either :
>
> - have as many independent Python interpreters at the same time ?

That's a question you should ask and discuss with Python developers.
(The current answer is 'no', as there is substantial global state in the
Python runtime.)

> - or encapsulate each plugin in an independent "environment" ?

Hard to tell without knowing these plugins. Right now it sounds like
that's a question only you can answer. :-)

> - or any other solution which would elegantly solve this problem ? :-D

Likewise.

Yes, I think the only possible way to solve this is to instantiate
Python first, and then let the plugins register with it, rather than
each plugin assume it was in control of "its" Python interpreter.
Or, if your plugins are heavyweight enough, you could run them within
their own proper address space (read: each in a separate process). But
you were asking for elegant solutions... :-)

> Thanks for your help,
> David

        Stefan

-- 
      ...ich hab' noch einen Koffer in Berlin...

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk