Multithreading 多线程蛮力函数

Multithreading 多线程蛮力函数,multithreading,python-2.7,brute-force,Multithreading,Python 2.7,Brute Force,我想知道我是如何使用多线程来处理蛮力函数的,我目前正试图学习如何利用多线程 charset = string.ascii_letters + string.digits def brute(real): attempts = 0 for password_length in range(1, 9): for guess in itertools.product(charset, repeat=password_length): attempts += 1

我想知道我是如何使用多线程来处理蛮力函数的,我目前正试图学习如何利用多线程

charset = string.ascii_letters + string.digits

def brute(real):
attempts = 0
for password_length in range(1, 9):
    for guess in itertools.product(charset, repeat=password_length):
        attempts += 1
        guess = ''.join(guess)
        if guess == real:
            return 'password is {}. found in {} guesses.'.format(guess, attempts)
        #print(guess, attempts)
使用打印命令调用该函数

print(brute(apass))
apass是使用另一个函数的变量集,是随机生成的密码

我是多线程新手,我想得到一些关于如何将其实现到这段代码中的帮助


(这个函数不是我自己做的,我只想对它应用多线程)

虽然你可以用Python做多线程,但要注意(至少在CPython中)你不会从中得到任何加速,因为Python使用了全局解释器锁(GIL)。如果您希望一次在多个核上执行时获得加速,请查看
多处理
Python模块。如何使用该多处理模块?我应该导入它吗?是的,您需要导入它才能使用它。我本人从未使用过它,我的理解是,它的设计使用方式与线程模块的使用方式类似;唯一的区别是,每个“线程”实际上是一个单独的进程(因此具有自己单独的GIL,因此不会减慢其他“线程”)。您可以在网上找到有关如何使用它的文档。