python 多处理没有启动

python multiprocessing doesn't start

我想使用 2 个单独的 CPU 内核、我的脚本和它的证据从一个大列表中打印 运行 下面是

它立即完成,我认为这 2 个过程不起作用

import multiprocessing as mp
import numpy as np

A = np.linspace(0,99999999,999999)

def print_stuff(i):
    for j in i:    # i want two seperate proccessores to print half of this list each 
        print(A[j]) 

def do_stuff():
    print("doing stuff")
    kk = range(int(len(A/2)))
    kk2 = []
    for i in kk:
        kk2.append(i+kk[-1])
    print(len(kk2))
    p1 = mp.Process(target = print_stuff, args = kk)
    p2 = mp.Process(target = print_stuff, args = kk2)
    print("done stuff")

if __name__ == "__main__":
    do_stuff()

进程需要用.start()方法启动

import multiprocessing as mp
import numpy as np

A = np.linspace(0,99999999,999999)

def print_stuff(i):
    for j in i:    # i want two seperate proccessores to print half of this list each 
        print(A[j]) 

def do_stuff():
    print("doing stuff")
    kk = range(int(len(A/2)))
    kk2 = []
    for i in kk:
        kk2.append(i+kk[-1])
    print(len(kk2))
    p1 = mp.Process(target = print_stuff, args = kk)
    p2 = mp.Process(target = print_stuff, args = kk2)

    # Starting threads
    p1.start()
    p2.start()

    # This will terminate the thread when they done their job(s)
    p1.join()
    p2.join()

    print("done stuff")

if __name__ == "__main__":
    do_stuff()