def __init__(self, *args, **kwargs): ''' Initialize local variables. All arguments will be passed into CoreThread. ''' # Call superclass constructor. CoreThread.__init__(self, *args, **kwargs) # Prepare a mutex to prevent concurrent race conditions when # modifying and accessing data in this object by multiple threads. self.access_lock = ReadWriteLock() # Initialize an empty mapping of (observation, state, state) to # a set of action classes. self.action_mapping = {} # Initialize an empty mapping of thread to a set of # (observation, state, state) tuples. self.thread_mapping = {} # Maintain a sequence of actions so that firing order is preserved. self.action_queue = Queue() # Maintain a counter of failed queue reads and a threshold after which # the read will wait. self.action_queue_read_counter = 0 self.action_queue_read_threshold = 3
def __init__(self, *args, **kwargs): ''' Initialize local variables. Ensure that extended classes call this constructor. This constructor calls both parent constructors. All arguments will be passed to CoreThread, none will be passed to CoreObservable. ''' # Call parent constructors CoreObservable.__init__(self) CoreThread.__init__(self, *args, **kwargs)
def __init__(self, observable, initial_state, final_state, *args, **kwargs): ''' Each action should be provided with an observable it is responding to and the state change which was observed. All additional arguments will be passed to CoreThread's constructor. ''' # By default, assume an action should run once but not loop. if not kwargs.has_key('do_loop') and len(args) < 3: kwargs['do_loop'] = False # Call superclass constructor CoreThread.__init__(self, *args, **kwargs) # Store this as stateful information to be used elsewhere. self.observable = observable self.initial_state = initial_state self.final_state = final_state