I have an array of threads. Each of them call the run method continuously. At the end of each run method I want them to pause and wait.
How can I get the threads to execute one at a time, and then continue the loop when all are finished? I need them to ALWAYS execute in order (ie: 1, 2, 3, 4 - 1, 2, 3, 4...)
I'm currently using threading.Event, but the results are inconsistent.
Thanks
UPDATE
Thanks everybody for your answers so far.
I'm writing something similar to Robocode in python. Players program a bot and the bots battle it out until one remains. After each "turn" the bots are "paused" then updated and drawn to the screen. Then they all start a new turn.
Example:
# Bot extends threading.Thread
class DemoBot(Bot):
def __init__(self):
super(DemoBot, self).__init__()
def run(self):
while True:
self.moveForward(100)
self.turnLeft(90)
As you can see, the bot is in an infinite loop. In the moveForward method, the bot would move forward 100px. But in order to update the screen correctly, I have to move once, pause, update, then move again. This is why I need to be able to "pause" a bot once its finished and have the program wait for the others before updating the screen.
Hope that makes a little more sense.