Looking for advice: supporting multiple embedded interpreters

David Bolen db3l at fitlinxx.com
Thu Jan 22 13:51:47 EST 2004


Paul Miller <paul at fxtech.com> writes:

> What I am wondering is if there a reliable method in 2.3 that does
> what I need?
> 
> It has recently come to my attention that Lutz Paelike is in exactly
> the same situation I am in, so I don't think this is a fringe concept.

I can't address why it doesn't work in 2.3, but just a question - have
you thought of not using independent interpreter states, but just
tracking the contents of sys.modules and clearing out any new modules
at reload time?  That would force even nested imports to be reloaded.
You can find an example of doing this in the unittestgui.py module,
for example, that is part of PyUnit, as it uses this approach to
ensure that all modules under test are reloaded at the start of
execution of a test suite.

I expect that you might be able to get even fancier by installing a
custom import hook, but just flushing sys.modules is pretty simple and
should work in any Python release.

Of course, it won't deal with stray references you may still have
around to the old module or module objects, but since the new
interpreter approach definitely can't be exhibiting that behavior
anyway, I expect you aren't using any older objects after such a
reload.

-- David



More information about the Python-list mailing list