IronPython threading in ACT


I try to use multithreading in ACT ironPython. The code is as follow:

# -*- coding: utf-8 -*-
import threading
import time
class PythonThreads():
    def __init__(self):
        self.threads = []

    def Add(self, func, args = None):
        t = self.Thread(func,args)

    def Run(self):
        for t in self.threads:

    def Join(self, Count = None, Label = None):
        for t in self.threads:

        for t in self.threads:
            if not t.is_alive() and Count != None:
                Count[0] += 1

    def GetResults(self):
        Results = [None] * len(self.threads)
        for index, t in enumerate(self.threads):
            Results[index] = t.getResult()
        return Results

    class Thread(threading.Thread):
        def __init__(self, func, args = (), name=''):
   = name
            self.func = func
            self.args = args

        def run(self):
            if self.args == None:
                self.args = ()
            self.result = self.func(*self.args)

        def getResult(self):
            return self.result

tt = PythonThreads()
def test():
    return 1

thread1 = PythonThreads()
t1 = time.time()

for i in range(3):
result = thread1.GetResults()
t2 = time.time()
print t2-t1
print result
# Results = tt.GetResults()
# ExtAPI.Log.WriteMessage(str(Results))

This can work using "C:\Program Files\ANSYS Inc\v231\commonfiles\IronPython\ipy.exe" in CMD command shell.
But in ACT, it is occur error.


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

    What is the t.getResult doing? Seems like you are doing multiple post processing at same time?

  • 1990chs
    1990chs Member Posts: 43
    First Comment Name Dropper
    edited February 20

    @Mike.Thompson said:
    What is the t.getResult doing? Seems like you are doing multiple post processing at same time?

    t.getResult is to get the function return result. This is from "Core Python Applications programming (third edition)" book.
    Yes, I try to use multi threads to extract the post result to reduce the time. But the IronPython version in workbench is 2.7.4, and it don't have multiprocessing module, so I only have to use threading module.