如何加速多进程python

如何加速多进程python,python,multiprocessing,python-imaging-library,mandelbrot,Python,Multiprocessing,Python Imaging Library,Mandelbrot,我正在尝试生成一个Mandelbrot集图像,但该图像需要很长时间。代码速度慢得让人恼火,所以如果你能帮我加快速度,那将非常有帮助。谢谢。请注意,代码是从我的IDE编译和运行的。我是多道处理新手,所以请帮我把它简化一下 def daemon_summoner(r): '''allows code to be restarted with different file if crash during super high res generation''' t = Thread(target=pr

我正在尝试生成一个Mandelbrot集图像,但该图像需要很长时间。代码速度慢得让人恼火,所以如果你能帮我加快速度,那将非常有帮助。谢谢。请注意,代码是从我的IDE编译和运行的。我是多道处理新手,所以请帮我把它简化一下

def daemon_summoner(r):
'''allows code to be restarted with different file if crash during super high res generation'''
t = Thread(target=process_job(r))
t.start()


def process_job(r):
    """creates a slice of the set"""
    img = Image.new('1', size, color)  # B&W image
    print(int(r + 2*resolution100+1), 'of', int(resolution100 *3))
    r = r * 100
    for rval in range(100):
        for i in range(-resolution, resolution, 1):
            if abrot(((r + rval) / resolution), (i / resolution * 1j)):
                try:
                    img.putpixel((rval, i + resolution,), 0)
                except:
                    print(r, rval, i + resolution)
img.save(('z_images/' + str(resolution) + '/' + str(int(r/100)+int(resolution*.02)) + '.png'))


def abrot(x, y):
    """tests a point"""
    c = (x + y)
    z = 0 + 0j
    for _ in range(5):
        z = z * z + c
    if abs(real(z*z+c))>=2and abs(imag(z*z+c))>=2:
        return False
    for _ in range(int(resolution / 10)):
        if real(z + 0.0001) > float(real(z*z+c)) > real(z - 0.0001):
            return True
        z = z * z + c
        if abs(real(z)) >= 2:
            return False
    return True

Mandelbrot迭代
z*z+c
可能需要数十亿次操作才能生成一幅图像,因此加快其速度的第一步是删除
iterate_once
函数并在线完成该工作