[IronPython] Statefulness of CompiledCode

Keith J. Farmer kfarmer at thuban.org
Tue May 27 05:33:52 CEST 2008

So what you want is a script initializer, right?  Try clearing SomeClass.fooListClassVariable at the start of your script.

I haven't used the CompiledCode feature, but from the looks of it, the script you get is bound to an engine which defines the execution scope.  IMHO, what you're seeing is the correct behavior.  You're executing some pre-compiled block of code multiple times against the same engine; it follows that execution would be stateful in this case.  

This isn't like executing the same application multiple times, since *that* involves a different process each time.  Instead, you're executing the same delegate method multiple times within a single process.

-----Original Message-----
From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Greg Parker
Sent: Monday, May 26, 2008 9:57 AM
To: Discussion of IronPython
Subject: Re: [IronPython] Statefulness of CompiledCode

Actually I do want a class variable as I described.  By design  
"fooListClassVariable" should be shared for all instances of "SomeClass" 
during one execution.  However, I don't want it to remember the value on 
subsequent calls to "compiledScript.Execute()", which is what is 
happening.  I would expect that every time I execute the CompiledCode it 
would not retain any state information about the last time it was 
executed.  This would be sort of like executing a c# application twice, 
and seeing class variables initialized to the values from the first 
execution.  Maybe I am misusing the CompiledCode class.

> If you want to see 1 printed for every iteration, do:
> class SomeClass:
>   def __init__(self):
>     self.fooListClassVariable = []
> etc. You want it to be an instance variable (which is initialized
> every time new instance is created), not a class variable (which is
> shared by all instances of the class).

Users mailing list
Users at lists.ironpython.com

More information about the Ironpython-users mailing list