Suppose we have the following code in IronPython:
def hello():
print "Hello from Python"
We call function hello() in the following C# code:
private static void GetPythonFunction()
{
ScriptRuntime scriptRuntime = IronPython.Hosting.Python.CreateRuntime();
ScriptScope scope = scriptRuntime.ExecuteFile(@"Python\helloFunc.py");
Action hello = scope.GetVariable<Action>("hello");
hello();
scriptRuntime.Shutdown();
hello(); // after IronPython runtime was disposed
}
Which gives us result:
Hello from Python
Hello from Python
Why the second call hello() works twice even though the runtime environment was disposed?