Python multiprocessing sharedctype array - cant write -
for testing reasons start 1 process. 1 given argument array shall changed process.
class engine(): ready = value('i', false) def movelisttoctypemovelist(self, movelist): ctml = [] 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 = [] in range(1): p = process(target=self.calculatenullmoves, args=(bd, movelist, i, self.ready)) process.append(p) p.start() 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 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): zug in ml: print (zug.vonreihe, zug.vonlinie, zug.nachreihe, zug.nachlinie, zug.bewertung) i try write 2.4 directly in list, no changing shown when calling "printctypemovelist". set "ready" true , works. used information http://docs.python.org/2/library/multiprocessing.html#module-multiprocessing.sharedctypes
i hope can find mistake, if difficult read, please let me know.
the problem you're trying share plain python list:
ctml = [] use proxy object instead:
from multiprocessing import manager ctml = manager().list() see python doc on sharing state between processes more detail.
Comments
Post a Comment