Project

General

Profile

« Previous | Next » 

Revision 1885

dicts.py: Turned id_dict() factory function into IdDict class. parallel.py: MultiProducerPool: Added share_vars(). main_loop(): Only consider the program to be done if the queue is empty and there are no running tasks.

View differences:

dicts.py
1 1
# Dictionaries
2 2

  
3
def id_dict(objects=[]):
4
    '''Makes a dict of objects by id() value'''
5
    return dict(((id(v), v) for v in objects))
3
import itertools
6 4

  
5
class IdDict(dict):
6
    '''A dict that stores objects by id()'''
7
    
8
    def add(self, *values):
9
        for value in values: self[id(value)] = value
10
        return self
11
    
12
    def add_vars(self, vars_): return self.add(*vars_.values())
13

  
7 14
class MergeDict:
8 15
    '''A dict that checks each of several dicts'''
16
    
9 17
    def __init__(self, *dicts): self.dicts = dicts
10 18
    
11 19
    def __getitem__(self, key):

Also available in: Unified diff