In article <[email protected]>, Thomas Jollans <[email protected]> wrote: >On 07/06/2010 09:11 PM, Aahz wrote: >> In article >> <[email protected]>, >> moerchendiser2k3 <[email protected]> wrote: >>> Aahz: >>>> >>>> Set sys.path to include each script's base dir before running it, then >>>> restore after each script. >>> >>> That works, but doesnt solve the problem. >>> >>> ScriptA.py has a module in its directory called 'bar.py' >>> ScriptB.py has a module in its directory called 'bar.py' >>> >>> Imagine the 'bar.py' modules dont have the same content, so they are >>> not equal. >>> >>> Now when the first bar.py is imported, the second import for a "import >>> bar" imports the first one, because its already stored in sys.modules. >> >> Good point, you'll need to save/restore sys.modules, too. That gets you >> 90-95% of complete namespace separation; if you need more than that, your >> best bet is to use separate processes. Full-blown namepace isolation is >> a *hard* problem, just look at all the past attempts to create secure >> Python (and what you're trying to do is roughly equivalent). > >I believe Python (at least in the 3.x series) supports multiple >interpreter instances per process.
Perhaps things have changed in 3.x, but although 2.x supposedly supported multiple interpreter instances per process, the impression I got was that most people would rather poke their eyes out with a dull stick than try to make multiple interpreters per process actually work. Multiple processes are easy, OTOH. -- Aahz ([email protected]) <*> http://www.pythoncraft.com/ "If you don't know what your program is supposed to do, you'd better not start writing it." --Dijkstra -- http://mail.python.org/mailman/listinfo/python-list
