0

テスト上の理由から、1 つのプロセスのみを開始します。与えられた引数の 1 つは、そのプロセスから変更される配列です。

class Engine():
Ready = Value('i', False)

def movelisttoctypemovelist(self, movelist):
    ctML = []
    for zug in movelist:
        ctZug = ctypeZug()
        ctZug.VonReihe = zug.VonReihe
        ctZug.VonLinie = zug.VonLinie
        ctZug.NachReihe = zug.NachReihe
        ctZug.NachLinie = zug.NachLinie
        ctZug.Bewertung = zug.Bewertung
        ctML.append(ctZug)
    return ctML

def findbestmove(self, board, settings, enginesettings):
    print ("Computer using", multiprocessing.cpu_count(),"Cores.")
    movelist = Array(ctypeZug, [], lock = True)
    movelist = self.movelisttoctypemovelist(board.movelist)
    bd = board.boardtodictionary()
    process = []
    for i in range(1):
        p = Process(target=self.calculatenullmoves, args=(bd, movelist, i, self.Ready))
        process.append(p)
        p.start()
    for p in process:
        p.join()
    self.printctypemovelist(movelist, settings)
    print ("Ready:", self.Ready.value)

def calculatenullmoves(self, boarddictionary, ml, processindex, ready):
    currenttime = time()
    print ("Process", processindex, "begins to work...")
    board = Board()
    board.dictionarytoboard(boarddictionary)
    ...
    ml[processindex].Bewertung = 2.4
    ready.value = True
    print ("Process", processindex, "finished work in", time()-currenttime, "sec")

def printctypemovelist(self, ml):
    for zug in ml:
        print (zug.VonReihe, zug.VonLinie, zug.NachReihe, zug.NachLinie, zug.Bewertung)

リストに直接 2.4 を書き込もうとしているのですが、「printctypemovelist」を呼び出しても変化が見られません。「Ready」をTrueに設定すると機能します。http://docs.python.org/2/library/multiprocessing.html#module-multiprocessing.sharedctypesの情報を使用しました

誰かが私の間違いを見つけてくれることを願っています。読むのが難しすぎる場合は、お知らせください。

4

1 に答える 1

0

問題は、プレーンな Python リストを共有しようとしていることです。

ctML = []

代わりにプロキシ オブジェクトを使用します。

from multiprocessing import Manager
ctML = Manager().list()

詳細については、プロセス間の状態の共有に関する Python ドキュメントを参照してください。

于 2013-10-08T16:41:33.177 に答える