Project

General

Profile

« Previous | Next » 

Revision 1857

bin/map: Use dummy synchronous Pool implementation if not using parallel processing

View differences:

map
29 29
import xml_func
30 30
import xml_parse
31 31

  
32
class Pool:
33
    def apply_async(func, args=None, kw_args=None, callback=None):
34
        if args == None: args = ()
35
        if kwds == None: kwds = {}
36
        if callback == None: callback = lambda v: None
37
        
38
        callback(func(*args, **kw_args))
39

  
32 40
def get_with_prefix(map_, prefixes, key):
33 41
    '''Gets all entries for the given key with any of the given prefixes'''
34 42
    values = []
......
115 123
    profiler = profiling.ItersProfiler(start_now=True, iter_text='row')
116 124
    
117 125
    # Parallel processing
118
    if cpus != 0:
119
        try:
120
            import multiprocessing
121
            import multiprocessing.pool
122
        except ImportError: pass
123
        else:
124
            if cpus == None: cpus = multiprocessing.cpu_count()
125
            job_server = multiprocessing.pool.Pool(processes=cpus)
126
            log_start('Using '+str(cpus)+' CPUs')
126
    try:
127
        if cpus == 0: raise ImportError('Parallel processing turned off')
128
        import multiprocessing
129
        import multiprocessing.pool
130
    except ImportError, e:
131
        log_start('Not using parallel processing: '+str(e))
132
        job_server = Pool()
133
    else:
134
        if cpus == None: cpus = multiprocessing.cpu_count()
135
        log_start('Using '+str(cpus)+' CPUs')
136
        job_server = multiprocessing.pool.Pool(processes=cpus)
127 137
    
128 138
    doc = xml_dom.create_doc()
129 139
    root = doc.documentElement

Also available in: Unified diff