0

i am trying to run a function in parallel with Multiprocessing starmap.

data = [(i, board) for i in range(board.width)]
        if __name__ == '__main__':
            p = mp.Pool(processes=mp.cpu_count())
            ratings = p.starmap(self.rate, data)
            print("Ratings: " + ratings)

My problem is that print is never executed. The Function just returns with None. self.rate() should return a number.

Github: https://github.com/Builder20/Connect4/tree/develop

Any ideas?

Builder_20
  • 27
  • 7

1 Answers1

0

Obvious the function loops. you can add logging to see which parts loops, I see the only candidate.

         while canSet == -1:
            opponentColumn = random.randint(0, board.width)
            canSet = board.setStone(self.other, opponentColumn)

add

logging.info(board)

to see how it progresses

Serge
  • 3,387
  • 3
  • 16
  • 34
  • It is calling itself until state is 3 then it should a result. – Builder_20 Jun 12 '20 at 18:36
  • Did not read the code, but you probably wrongly assume that processes can share an object – Serge Jun 12 '20 at 18:37
  • Maybe, this is my first try with Multiprocessing in Python. So you think it cannot interact/reach board? – Builder_20 Jun 12 '20 at 18:39
  • Ok. So my problem is that I try to use board as shared resource and I need to get one Instance per process? – Builder_20 Jun 12 '20 at 19:01
  • Not sure is it the only issues. btw there are ways to share data between threads https://stackoverflow.com/a/5550156/5874981 https://docs.python.org/2/library/multiprocessing.html – Serge Jun 12 '20 at 19:41