Multiprocessing/Multithredding Python 2.7 中的 3 个嵌套循环

Multiprocessing/Multithredding 3 nested loops in Python 2.7

我有以下代码片段:

for x in xrange(100,14000):
    for y in xrange(0,3000):
        for z in xrange(0,700):
            operationg_tag = "%s-%s-%s" % (x,y,z)
            operation_code = ....

            and more bunch of code is running here on the tag generated above

我运行在一个快速的好硬件中使用这个代码,但是这些循环的性质很慢,因为 Multiprocessing/Multithredding

中没有 运行ning

在每个标签上执行所需的代码大约需要 0.4 秒。

如何在这些嵌套循环中实现 Multiprocessing/Multithredding 以使其 运行 更快?我应该针对哪个循环?

打破第 3 个过程中的第一个循环,

    def func(start, final):
         for x in xrange(start, final):
              for y in xrange(0,3000):
                   for z in xrange(0,700):
        operationg_tag = "%s-%s-%s" % (x,y,z)
        operation_code = ....
    def main():
        total = 14000
        div_total = int(14000 / 3)
        rest_div_total = 14000%3
        t1 = multiprocessing.Process(target = func,name = "", args=(100, div_total)
        t2 = multiprocessing.Process(target = func,name = "", args=(div_total, div_total*2)
        t3 = multiprocessing.Process(target = func,name = "", args=(div_total*2, div_total*3 + rest_div_total + 1)
        list_threads = [t1,t2,t3]
        for i in list_threads:
           i.start()
        for i in list_threads:
           i.join()

    if __name__ == "__main__":
        main()

如果愿意,您可以创建更多进程,但是 3 个就足够了。