0

我在 python 中编写了一个数独求解器,它使用递归函数来遍历数独板的所有可能排列。该程序线性地解决了数独难题,我试图通过将任务分成不同的线程来使其更快。然而,经过对线程的大量思考和研究,我仍然不知道如何在我的函数中实现线程。这是我的功能顺便说一句

def solve(num,possible,temp):
    y = num%9
    x = num-y
    try:
        for xyz in possible[num]:
            if num != 80:
                if ispossibility(temp,xyz,x,y) == True:
                    temp[num] = xyz
                    solution = solve(num+1,possible,temp)
                    if solution != None:
                        raise exception
                temp[num] = 0
            else:
                if ispossibility(temp,xyz,x,y) == True:
                    temp[num] = xyz
                    solution = copy(temp)
                    raise exception
    except exception:
        return solution 

所以我想要一个单独的线程来运行“solution = solve(num+1, possible, temp)”这一行,但问题是一旦一个线程找到答案,我无法弄清楚如何停止所有单独的线程。关于做什么的任何指示?

4

0 回答 0