[IronPython] Statefulness of CompiledCode

Greg Parker greg.parker at brovada.com
Mon May 26 20:12:09 CEST 2008


Thanks for the suggestions.  I tried the reload statement in the python 
script itself.  I executed the same application in a tight loop about 
1000 times.  The VM Size skyrocketed to ~500M (without the reload it 
stays at ~16M).  So this doesn't look like an option for me, especially 
since the actual script we are trying to run is much larger and more 
complicated.  As for changes to the C# code, in 1.1 if I try to clear 
the globals I just get an exception ('module' object has no attribute 
'__builtins__').  So am I better off just using the latest 2.0 build?  
Which frameworks does it run on?  Thanks again

Korbinian Abenthum wrote:
> AFAIK the import statement creates a new Scope for the imported module 
> that lives in parallel to the ScriptScope passed to Execute (in IP2, I 
> don't know about 1.1). Since import will check if the module was 
> imported before, it is only imported during the first iteration and 
> the class variable of SomeClass will persist during all you calls to 
> Execute.
>
> It should work to "import SomeInclude; reload(SomeInclude)" at the 
> beginning or end of each execution. On the C# side, if I add
>  python.Runtime.Globals.ClearVariables();
> before or after each call to execute, it removes the (references to 
> the) imported scopes and will load them anew during the next execution,
> but I do not know if this is the cleanest way to do so.
>
> | ScriptEngine python = IronPython.Hosting.PythonEngine.CurrentEngine;
> | CompiledCode compiledCode = 
> python.CreateScriptSourceFromFile("Program.py").Compile();
> | ScriptScope scope = python.CreateScope();
> | | for (int i = 0; i < 10; i++)
> | {
> |     compiledCode.Execute(scope);
> |     python.Runtime.Globals.ClearVariables();
> | }
> _______________________________________________
> Users mailing list
> Users at lists.ironpython.com
> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com




More information about the Ironpython-users mailing list