[Ironpython-users] How to forcibly terminate a script?

Jeff Hardy jdhardy at gmail.com
Wed Mar 26 13:47:35 CET 2014


The only way to forcibly end it is to run it in another thread and use
Thread.Abort[1]. All of the usual caveats around Thread.Abort apply, and
your atexit may or may not be called.

The Shutdown method is a bit misleading; it does some cleanup but doesn't
actually *stop* the current engine. There really isn't any way to do that,
and any implementation would probably be the moral equivalent of
Thread.Abort anyway.

- Jeff

[1] http://msdn.microsoft.com/en-us/library/ty8d3wta.aspx


On Wed, Mar 26, 2014 at 11:10 AM, Andrew Stephens <
Andrew.Stephens at nu-ins.com> wrote:

>  Let's say I run the following simple script (which also contains an
> "atexit" func, as I might want to perform some cleanup when the script
> terminates):-
>
>
>
> import atexit
>
> import time
>
> import sys
>
>
>
> @atexit.register
>
> def cleanup():
>
>     print 'doing cleanup/termination code'
>
>     sys.exit()
>
>
>
> for i in range(100):
>
>     print 'doing something'
>
>     time.sleep(1)
>
>
>
> If I call "_engine.Runtime.Shutdown()" in my C# code, it results in the
> atexit func getting called and raising a SysExitException in the calling C#
> code (due to the line "sys.exit()"), but the "for" loop still continues to
> run to completion.
>
> What am I missing? Is it possible to forcibly terminate a running script
> with IronPython?
>
>
>
>
>
> Andrew Stephens
>
> Senior Software Engineer
>
> Nu Instruments Ltd
>
>
>
> Email: Andrew.Stephens at nu-ins.comTel: +44 (0) 1978 661304Fax: +44 (0)
> 1978 664301Web:www.nu-ins.com
>
>
>
>
>
> *Nu Instruments Ltd*
> Unit 74 Clywedog Road South
> Wrexham Industrial Estate
> Wrexham LL13 9XS
> United Kingdom
>
> *Disclaimer*
>
> This message is confidential and may contain privileged information and is
> protected by copyright. If you are not the intended recipient you should
> not copy or disclose this message to anyone but should kindly notify the
> sender and delete the message. Opinions, conclusions and other information
> in this message which do not relate to the official business of Nu
> Instruments Ltd shall be understood as neither given nor endorsed by it. No
> contracts shall be concluded by means of this email. Neither the Company
> nor the sender accepts any responsibility or liability for any loss or
> damage arising from the presence of any computer virus or similar harmful
> code contained in this email or attachment/s.  It is your responsibility to
> scan this email and any attachments. The Company reserves the right to
> access and disclose all messages sent over its email system.
>
> Nu Instruments Ltd is registered in England, No.: 3046042. Registered
> Office: Seacourt Tower, West Way, Oxford OX2 0FB. VAT No.: GB 616 3733 45
>
>
> _______________________________________________
> Ironpython-users mailing list
> Ironpython-users at python.org
> https://mail.python.org/mailman/listinfo/ironpython-users
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/ironpython-users/attachments/20140326/941a94c1/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 1ebda7.png
Type: image/png
Size: 5791 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/ironpython-users/attachments/20140326/941a94c1/attachment.png>


More information about the Ironpython-users mailing list