[Python] Python Multiprocessing error: AttributeError: Can't get attribute 'task' on <module...

Discussão em 'Python' iniciado por Stack, Dezembro 7, 2024.

  1. Stack

    Stack Membro Participativo

    I'm using spyder 5.1.5 and I am trying to follow along with the very first example on a website. I'm getting the error:

    AttributeError: Can't get attribute 'task' on <module '__main__' (built-in)>


    task is a function that I define.

    Full example code:

    import multiprocessing
    import time

    def task(num):
    print("a",num)
    time.sleep(2)
    if __name__ == '__main__':
    for i in range(10):
    p = multiprocessing.Process(target=task,args=(i,))
    p.start()

    Continue reading...

Compartilhe esta Página