I have this loop:
listGames = []
for home in range(totalPlayers - 1):
for away in range(home + 1, totalPlayers):
listGames.append((home, away))
print listGames
match_num = 1
for game in listGames:
player1 = listPlayers[game[0]]
player2 = listPlayers[game[1]]
do_stuff(player1, player2)
When there are a lot of players, this loop can take quite some time, so is want to use threads to complete the loop faster. However, player1 and player2 are instances of classes, so doing stuff with them simultaneously would be bad. EDIT: The order in which these 'tasks' are executed does not matter otherwise.
I found http://www.troyfawkes.com/learn-python-multithreading-queues-basics/ which seems to be exactly what I want, but I am unsure how to adapt it to make sure that only 1 instance of the class/player is being run at once
(Simple) example:
totalPlayers = 4
0, 1, 2, 3
listGames = [(0, 1), (0, 2), (0, 3), (1, 2), (1, 3), (2, 3)]
so, game (0, 1), (2, 3) can be executed simultaneously, but the others will have to wait until these are done
Hints/Ideas?