[Python] Why is multiprocessing module not producing the desired result?

Discussão em 'Python' iniciado por Stack, Janeiro 19, 2025.

  1. Stack

    Stack Membro Participativo

    [​IMG]

    import multiprocessing as mp
    import os

    def cube(num):
    print(os.getpid())
    print("Cube is {}".format(num*num*num))

    def square(num):
    print(os.getpid())
    print("Square is {}".format(num*num))

    if __name__ == "__main__":
    p1 = mp.Process(target = cube, args = (3,))
    p2 = mp.Process(target = square, args = (4,))
    p1.start()
    p2.start()
    p1.join()
    p2.join()
    print("Done")


    [​IMG]

    I was using the multiprocessing module, but I am not able to print any output from a function using that.

    I even tried flushing the stdout using the sys module.

    Continue reading...

Compartilhe esta Página