Eryk Sun <eryk...@gmail.com> added the comment:

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

The Windows API only supports the spawn method of process creation. In POSIX 
(except macOS), the default is the fork method, for which the child inherits 
the interactive main module of the parent. If you switch to the spawn method in 
Linux via multiprocessing.set_start_method('spawn'), you'll see the same error. 

multiprocessing is one package where it's necessary in Windows to test examples 
using a script. This is implied in the guidelines when it says to "[m]ake sure 
that the main module can be safely imported by a new Python interpreter without 
causing unintended side effects (such a starting a new process)". It's the fact 
the main module has to be importable by child processes that matters in this 
case. The behavior is noted with an example at the end of the introduction:

    Note
    Functionality within this package requires that the __main__ module
    be importable by the children. This is covered in Programming 
    guidelines however it is worth pointing out here. This means that 
    some examples, such as the multiprocessing.pool.Pool examples will 
    not work in the interactive interpreter. For example: ...

If it were up to me this note would be at the beginning of the introduction, 
where everyone would certainly see it. As is, the reader is expected to at 
least scan over the entire introduction.

----------
nosy: +eryksun

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue45914>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to