2

I have a program which embeds Python (via Boost.Python), and provides an 'extension' framework. I wish to unify these two parts by allowing extensions to load a set of Python bindings for their API, however I'm confused as to how I would I 'unregister' these APIs when the plugin is unloaded.

Is this even possible with Python and Boost.Python? I know it's not possible with Lua and LuaBind, as the documentation indicates it's impossible to 'unbind' an API.

Sorry for how poorly this question is written, it's 2:30 AM here and I've been at it a while. ;)

RaptorFactor
  • 2,810
  • 1
  • 29
  • 36

1 Answers1

3

There is a related discussion about unloading/reloading python modules. Check out the 3rd answer (here), the one that starts off with:

To cover my shame, here is a Python list thread that discusses how to delete a module. The summary: it can be especially difficult if the module is not pure python.

Community
  • 1
  • 1
André Caron
  • 44,541
  • 12
  • 67
  • 125
  • Using the approach given in that post, objects left over that are still using types exposed by the modules are still 'alive', so if I then unload the module attempts to use said objects will crash the program. Is there any way I can force all existing objects that are 'owned' by that module (or rather, user-created but using types exposed by the module) to be deleted automatically? – RaptorFactor Nov 01 '10 at 16:59
  • I don't think there is any built-in support for that. It would have strange consequences anyways, because lots of object references would suddenly become `None`. The only clean solution, AFAIK, is to construct your program such that all those objects are freed, and *then* the module is unloaded. This is probably the reason behind not having native support for module unloading in the first place! – André Caron Nov 01 '10 at 18:02