示例#1
0
 def worker(number):
     factors = factorise(number)
     return count_uniques(factors)
示例#2
0
    print
    print "mode:"
    print "  s for serial"
    print "  m for multiprocessing"
    print "  i for IPython"
    exit()


# Start factorisation
start = 2
end = 500000
uniques = []

if mode == 's':
    for number in range(start, end + 1):
        factors = factorise(number)
        uniques.append(count_uniques(factors))

elif mode == 'm':
    def worker(number):
        factors = factorise(number)
        return count_uniques(factors)

    pool = Pool(processes=multiprocessing.cpu_count())
    result = pool.map_async(worker, range(start, end + 1))
    uniques = result.get()

elif mode == 'i':
    try:
        cli = Client()
    except IOError: