所以我正在进行迭代深化的多进程国际象棋搜索 算法,它目前工作。不幸的是,有时程序会在except块中的某处停顿。当它停止时会有7个僵尸孩子(我在8核机器上运行,所以我创建了7个进程)。这种情况相当罕见,但在我的程序实际播放时,每千次移动会发生几次。
似乎只发生在linux / mac机器上。我希望我的搜索在10秒后停止并返回前一个movelist的值。
有关如何调试或解决此问题的任何建议?
def search(board, maxDepth, maxTime):
start = time.time()
threadData = [[i, None, 0, board] for i in board.legal_moves]
threads = min(len(threadData), cpu_count()-1)
pool = ThreadPool(processes=threads)
moveList = []
gotDepth = -1
for depth in range(0, maxDepth):
# set the current depth to search
for i in range(len(threadData)):
threadData[i][2] = depth
result = pool.map_async(moveThreading, threadData)
try:
threadData = result.get(maxTime - (time.time() - start))
gotDepth = depth
threadData = sorted(threadData, key=itemgetter(1), reverse=True)
moveList = [[item[0], item[1]] for item in threadData]
except TimeoutError:
#Diagnostic printing for analysis after game is played
if DIAGNOSTIC:
with open("diagnostic.txt", "a") as f:
f.write("@"+str(depth-1)+'==')
for i in moveList:
f.write("['"+str(i[0])+"'_"+str(i[1])+']')
f.write('\n')
pool.terminate()
pool.join()
pool = None
break
return gotDepth, moveList