An alternate plan would be to run your script in another app domain.  Then you 
can just unload the app domain and all shared state will be cleared.  The 
hosting APIs make this pretty easy to do as well.

From: users-boun...@lists.ironpython.com 
[mailto:users-boun...@lists.ironpython.com] On Behalf Of Curt Hagenlocher
Sent: Monday, January 19, 2009 6:22 AM
To: Discussion of IronPython
Subject: Re: [IronPython] Stop script execution/unload script

Your intuition that you're running a kind of script that can be stopped is 
leading you astray. :)

When you program in IronPython, it's very much like programming in C# -- the 
objects you create will stay alive until they are garbage collected or the 
program ends.  So to unhook the delegate from the event, you need to do the 
same thing from IronPython that you would have done from C#:

Button1.Click -= hello.

I believe that Runtime.Shutdown() will call any "atexit" methods you defined 
from Python, so you can use this to perform cleanup.
On Mon, Jan 19, 2009 at 5:55 AM, TommyN <t...@vizrt.com<mailto:t...@vizrt.com>> 
wrote:

Hi,

I've been testing using IronPython as an embedded script language in a small
C# application. I have added some code to a winform buttons Click event with
code like this:

def hello(s, e):
 MessageBox.Show('Clicked ' + s.Name)
Button1.Click += hello;


This works fine, but the problem is that if I modify the script code at
run-time and call:

source.Engine.Runtime.Shutdown();
source = engine.CreateScriptSourceFromString(....);
..
source.Execute(..)

I suddenly have 2 scripts running at the same time, and the messagebox is
displayed twice.
How should I go about properly stopping/unloading the first instance of the
script so only the latest script will be executed?

Any pointers would be greatly appreciated!
-Tommy

--
View this message in context: 
http://www.nabble.com/Stop-script-execution-unload-script-tp21542133p21542133.html
Sent from the IronPython mailing list archive at Nabble.com.

_______________________________________________
Users mailing list
Users@lists.ironpython.com<mailto:Users@lists.ironpython.com>
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com

_______________________________________________
Users mailing list
Users@lists.ironpython.com
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com

Reply via email to