[IronPython] Clearing context

Curt Hagenlocher curt at hagenlocher.org
Wed Jan 9 18:15:53 CET 2008


On Jan 9, 2008 8:54 AM, Slide <slide.o.mix at gmail.com> wrote:
>
> If I change this file and try reloading my script, it takes the
> modifications just fine and runs the new code. If I modify mymod, but
> not the main script, I get the old code from mymod run. Is there
> something I can do to force it to reload the imported scripts as well?

There's no straightforward and reliable way to track usage, so the
only thing you could do generically is to reload *all* your modules.
One thing you could do would be to say "import mymod" in any other
module using mymod.  After a reload of mymod, you could then iterate
over sys.modules and reload any module containing the symbol "mymod".
It's not foolproof, but it's probably good enough.

Another alternative would be to change your code to look like this:

class MyClass(SomeNameSpace.IMyInterface):
    def SomeFunc(self):
        from mymod import myfunc
        myfunc()

That way, the import gets re-run each time you run SomeFunc, and
you'll always get the latest version of the module.

--
Curt Hagenlocher
curt at hagenlocher.org



More information about the Ironpython-users mailing list