CTRL-C style interrupt of IronPython scripts in the Workbench Mechanical scripting interface?


I run scripts in the Mechanical GUI.

Sometimes, it would be convenient to interrupt a script.

However, the scripting interface in Mechanical does not respond to CTRL-C input, which would interrupt my script if I ran it in an ironpython console window.

My question: Is there any way to interrupt a running script using a) keyboard inputs or b) another method?

Thank you!


Best Answer

  • Mike.Thompson
    Mike.Thompson Member, Employee Posts: 300
    First Anniversary First Comment 5 Likes Ansys Employee
    Answer ✓

    I don’t think this is possible. You can code checks to see if a file exists and then externally create that file when you want code to exit. That is the best I have been able to come up with. Mechanical is locked up while code is executing and does not support multi threaded code.


  • augustbrandberg
    augustbrandberg Member Posts: 8
    Name Dropper First Comment
    edited January 30

    Ok, then I will use a file existence check. Thank you!

  • augustbrandberg
    augustbrandberg Member Posts: 8
    Name Dropper First Comment

    Minimal implementation for future me and others interested:

    import os
    def abort_requester_check(abort_file):
        if os.path.isfile(abort_file):
            raise IOError("Aborting due to existence of abort file " + abort_file)
    counter = 0
    while True:
        counter += 1