N
N
Nicholas V2018-02-20 12:09:03
Python
Nicholas V, 2018-02-20 12:09:03

Why doesn't the example from the documentation for the multiprocessing module work?

I open the module documentation , copy the first or, for example, the second example in the IDE:

from multiprocessing import Process

def f(name):
    print('hello', name)

if __name__ == '__main__':
    p = Process(target=f, args=('bob',))
    p.start()
    p.join()

And I get this error:
>>> Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "C:\Python36\lib\multiprocessing\spawn.py", line 105, in spawn_main
    exitcode = _main(fd)
  File "C:\Python36\lib\multiprocessing\spawn.py", line 115, in _main
    self = reduction.pickle.load(from_parent)
AttributeError: Can't get attribute 'f' on <module '__main__' (built-in)>

The same thing if you enter through the terminal. Nothing happens in standard IDLE.
Other examples - for example, from the threading module are launched without problems. Why something complexity precisely with this oroy. At least something starts to work only if you use multiprocessing.dummy instead of the multiprocessing module , but it seems that these are again threads, not processes. (WIn10 x64 - Python recently updated to 3.6.4) What could be the problem?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question