[IronPython] Stopping, Closing, and Unloading of running IronPython code?

Dino Viehland dinov at microsoft.com
Wed Feb 9 17:09:33 CET 2011


Doug wrote:
> If you have embedded IronPython engines (and perhaps a few other DLR
> languages) running in a thread, what is the recommended method of
> stopping the running programs, and calling the objects' delete methods?
> 
> For example, say you have a serial port open in an IronPython program
> running in a thread, and you want to stop the thread, and close the port? Is
> there something general that would take care of all closing, just like it would
> if you killed a process?
> 
> Thanks for any suggestions,

You can run the code in an app domain and then just unload the app domain.  Any
code running in the app domain will be Thread.Abort'd by the CLR and all of the 
finalizers will run once the threads have been killed - and that should close the 
serial port or any other resources.

Any code with finally blocks and the such will still be given a chance to cleanup
as well.



More information about the Ironpython-users mailing list