Thread

from threading import Thread
t = Thread(target=funtion, args=(parameter1, parameter2))
#新增一个线程
t.setDaemon(True)
#将线程声明为守护线程,必须在start() 方法调用之前设置,如果不设置为守护线程程序会被无限挂起
t.start()
#开始线程
t.join()
#等待子线程执行完毕再执行父线程

For example:

一个采用多线程进行zip密码破解的脚本

#coding=utf8
#usage:python zipcracker.py xxx.zip xxx.txt
import zipfile
from threading import Thread
import sys

def extractFile(zFile, password):
    try:
        zFile.extractall(pwd=password)
        print password
    except Exception as e:
        pass


def main():
    file=sys.argv[1]
    pwd=sys.argv[2]
    zFile = zipfile.ZipFile(file)
    passFile = open(pwd)
    for line in passFile.readlines():
        password = line.strip('\n')
        t = Thread(target=extractFile, args=(zFile, password))
        t.start()


if __name__ == '__main__':
    main()