def run(self): for number, item in queue_tools.iterate(self.work_queue, block=True): if number in self.library: assert self.library[number] is item other_items = [value for (key, value) in self.library.items() if key != number] for other_item in other_items: assert other_item is not item self.processed_items_queue.put(item) self.message_queue.put('Asserted identity.') else: # number not in self.library self.library[number] = item self.processed_items_queue.put(item) self.message_queue.put('Stored object.')
def __add_work_to_tree(self, cruncher, job, retire=False): ''' Take work from cruncher and add to tree at the specified job's node. If `retire` is set to `True`, retires the cruncher. Keep in mind that if the cruncher gives an `EndMarker`, it will be retired regardless of the `retire` argument. Returns `(number, leaf)`, where `number` is the number of nodes that were added, and `leaf` is the last node that was added. ''' tree = self.project.tree node = job.node current_node = node counter = 0 queue_iterator = queue_tools.iterate( cruncher.work_queue, limit_to_original_size=True, _prefetch_if_no_qsize=True ) for thing in queue_iterator: if isinstance(thing, garlicsim.data_structures.State): counter += 1 current_node = tree.add_state( thing, parent=current_node, step_profile=self.step_profiles[cruncher], ) # todo optimization: save step profile in variable, it's # wasteful to do a dict lookup every state. elif isinstance(thing, EndMarker): tree.make_end(node=current_node, step_profile=self.step_profiles[cruncher]) job.resulted_in_end = True else: raise TypeError('Unexpected object `%s` in work queue' % thing) if retire or job.resulted_in_end: cruncher.retire() nodes_added = garlicsim.misc.NodesAdded(counter) return (nodes_added, current_node)
def __add_work_to_tree(self, cruncher, job, retire=False): ''' Take work from cruncher and add to tree at the specified job's node. If `retire` is set to `True`, retires the cruncher. Keep in mind that if the cruncher gives an `EndMarker`, it will be retired regardless of the `retire` argument. Returns `(number, leaf)`, where `number` is the number of nodes that were added, and `leaf` is the last node that was added. ''' tree = self.project.tree node = job.node current_node = node counter = 0 queue_iterator = queue_tools.iterate(cruncher.work_queue, limit_to_original_size=True, _prefetch_if_no_qsize=True) for thing in queue_iterator: if isinstance(thing, garlicsim.data_structures.State): counter += 1 current_node = tree.add_state( thing, parent=current_node, step_profile=self.step_profiles[cruncher], ) # todo optimization: save step profile in variable, it's # wasteful to do a dict lookup every state. elif isinstance(thing, EndMarker): tree.make_end(node=current_node, step_profile=self.step_profiles[cruncher]) job.resulted_in_end = True else: raise TypeError('Unexpected object `%s` in work queue' % thing) if retire or job.resulted_in_end: cruncher.retire() nodes_added = garlicsim.misc.NodesAdded(counter) return (nodes_added, current_node)
def run(self): for number, item in queue_tools.iterate(self.work_queue, block=True): if number in self.library: assert self.library[number] is item other_items = [ value for (key, value) in self.library.items() if key != number ] for other_item in other_items: assert other_item is not item self.processed_items_queue.put(item) self.message_queue.put('Asserted identity.') else: # number not in self.library self.library[number] = item self.processed_items_queue.put(item) self.message_queue.put('Stored object.')
def __add_work_to_tree(self, cruncher, node, retire=False): ''' Take work from the cruncher and add to the tree at the specified node. If `retire` is set to True, retires the cruncher. Returns (number, leaf), where `number` is the number of nodes that were added, and `leaf` is the last node that was added. ''' #todo: modify this to take job? tree = self.project.tree current = node counter = 0 self.step_profiles[cruncher] for thing in queue_tools.iterate(cruncher.work_queue): if isinstance(thing, garlicsim.data_structures.State): counter += 1 current = tree.add_state( thing, parent=current, step_profile=self.step_profiles[cruncher], ) # todo optimization: save step profile in variable, it's # wasteful to do a dict lookup every state. elif isinstance(thing, StepProfile): self.step_profiles[cruncher] = thing else: raise Exception('Unexpected object in work queue') if retire: cruncher.retire() nodes_added = garlicsim.misc.NodesAdded(counter) return (nodes_added, current)