itertools多处理需要指导

问题描述 投票:-1回答:1

我试图制作一个蛮力的应用程序,但是我试图实现多处理,但是我没有头绪。我检查了所有文档和StackOverflow,但似乎无济于事。这是要并行化的代码。这是输入,功能裂纹应进行多处理。

UPPER_ALPHA = ['Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', 'O', 'P', 'A', 'S', 'D',
               'F', 'G', 'H', 'J', 'K', 'L', 'Z', 'X', 'C', 'V', 'B', 'N', 'M', ]
LOWER_ALPHA = [al.lower() for al in UPPER_ALPHA]

def crack(w_input):
    GEN = list(itertools.product(w_input, repeat=4))
    return GEN
python multiprocessing itertools brute-force
1个回答
0
投票
from multiprocessing import Pool 

#Function for single process
def function(val):
    return val*4

# Function for handling multiprocessing
def handler(function, data, workers=4):

    with Pool(workers) as pool:
        r = pool.map(function, data)
        return r

data = [1,2,4,5,6,7,8,9,10,11,12]
GEN = handler(function,data, workers=4)
© www.soinside.com 2019 - 2024. All rights reserved.