[Python] Multiprocessing example giving AttributeError in Jupyter Notebook

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

  1. Stack

    Stack Membro Participativo

    I am trying to implement multiprocessing in my code, and so, I thought that I would start my learning with some examples. I used the first example found in this documentation.

    from multiprocessing import Pool
    def f(x):
    return x*x

    if __name__ == '__main__':
    with Pool(5) as p:
    print(p.map(f, [1, 2, 3]))


    When I run the above code I get an AttributeError: can't get attribute 'f' on <module '__main__' (built-in)>. I do not know why I am getting this error. I am also using Python 3.5 if that helps.

    Continue reading...

Compartilhe esta Página