Getting issue while invoke callback in separate thread in ACT

Options
dafedin
dafedin Member Posts: 21
First Comment Name Dropper
edited October 2023 in General Language Questions

Hello,

In ACT for Mechanical Context, I have a callback which is called on the button click implemented in XML:

<callbacks><onclick>run</onclick></callbacks>

The run() routine is initialized in .py file as
run(context)
In such a case, the button is being pressed during the runtime of ACT, and UI is suspended. It looks normal because no separate thread is created for run(). Then I changed the code to run ACT in a separate thread and to release UI by putting the main code to another routing:

def main():
    def internal_main():
           ...
    thread = System.Threading.Thread(System.Threading.ThreadStart(internal_main))
    thread.Start()

def run(context):
    main()

but get the Static Structural closed with the error message "ansysWB encountered a problem ..." instead of execution!
What is the reason why the solution is crushed? Is the technique mentioned above the right way to release UI during the ACT run?

Thanks

Answers

  • Mike.Thompson
    Mike.Thompson Member, Employee Posts: 279
    First Anniversary First Comment 5 Likes Ansys Employee
    Options

    I think it really depends on what you are doing on the asynchronous thread. Mechanical does not support multithreading, so anything you do on that thread, cannot interact with the Mechanical DataModel. You could do some thing like read data from an external file, since this has nothing to do with the Mechanical DataModel.

  • dafedin
    dafedin Member Posts: 21
    First Comment Name Dropper
    Options

    Hello Mike!

    Thank You for Your suggestion. The ACT code starts the solution with the overridden properties and processes the solution results using the DPF framework sequentially. Not sure about the solution stage but the post-processing stage could be done in the background. Isn't it?

    Thanks

  • Mike.Thompson
    Mike.Thompson Member, Employee Posts: 279
    First Anniversary First Comment 5 Likes Ansys Employee
    Options

    Yea, I believe post processing with DPF could be done on another thread as this does not interact with the Mechanical DataModel