Example #1
0
class Baton(object):
    """The Conductor's instrument for synchronizing the players.
    """
    def log(self, cp):
        log_lock.acquire()
        import inspect
        func_name = inspect.currentframe().f_back.f_code.co_name
        print("{} in {} waiting on {}".format(threading.current_thread().name, func_name, cp))
        log_lock.release()

    def __init__(self, checkpoint_order):
        self.player_event = CascadingEventGroup(checkpoint_order, 'player evt.')
        self.conductor_event = CascadingEventGroup(checkpoint_order, 'conductor evt')
        self.log_lock = threading.Lock()

    def wait_for_permission(self, checkpoint):
        # self.log(checkpoint)
        self.player_event.wait_on(checkpoint)

    def yield_permission(self, checkpoint):
        # self.log(checkpoint)
        self.player_event.done_with(checkpoint)

    def wait_acknowledgement(self, checkpoint):
        # self.log(checkpoint)
        self.conductor_event.wait_on(checkpoint)

    def acknowledge_checkpoint(self, checkpoint):
        # self.log(checkpoint)
        self.conductor_event.done_with(checkpoint)
Example #2
0
 def __init__(self, checkpoint_order):
     self.player_event = CascadingEventGroup(checkpoint_order, 'player evt.')
     self.conductor_event = CascadingEventGroup(checkpoint_order, 'conductor evt')
     self.log_lock = threading.Lock()