This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author eryksun
Recipients eryksun, paul.moore, quattrozhou, steve.dower, tim.golden, zach.ware
Date 2021-11-28.05:27:57
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1638077277.6.0.235337794313.issue45914@roundup.psfhosted.org>
In-reply-to
Content
> 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.
History
Date User Action Args
2021-11-28 05:27:57eryksunsetrecipients: + eryksun, paul.moore, tim.golden, zach.ware, steve.dower, quattrozhou
2021-11-28 05:27:57eryksunsetmessageid: <1638077277.6.0.235337794313.issue45914@roundup.psfhosted.org>
2021-11-28 05:27:57eryksunlinkissue45914 messages
2021-11-28 05:27:57eryksuncreate