[issue34891] Multi-processing example inaccurate warning

New submission from Anthony Flury <anthony.flury@btinternet.com>: On the Multi-processing page <https://docs.python.org/3/library/multiprocessing.html> (just above the reference section) there is a warning that the examples wont work from the interpreter. This is not entirely accurate in that the examples do work, in the interpreter within Linux (and Mac OS I think), where the O/S supports processes being forked. In fact it is only in Windows, where a brand new process needs to be started and the source is effectively re-imported is there an issue running the examples in the interpreter. Should the documentation make this clearer ? ---------- assignee: docs@python components: Documentation messages: 327046 nosy: anthony-flury, docs@python priority: normal severity: normal status: open title: Multi-processing example inaccurate warning versions: Python 3.8 _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue34891> _______________________________________

Karthikeyan Singaravelan <tir.karthi@gmail.com> added the comment: Thanks for the report. Are you referring to the below warning?
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:
I tried the example and it throws the AttributeError as shown in the example in Linux and MacOS. Maybe I am wrong on the above. Can you please add in the specific example that is shown as not executable from the interpreter but actually works? Thanks ---------- nosy: +xtreak _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue34891> _______________________________________

Anthony Flury <anthony.flury@btinternet.com> added the comment: An example that does work : $ python3 Python 3.6.6 (default, Sep 12 2018, 18:26:19) [GCC 8.0.1 20180414 (experimental) [trunk revision 259383]] on linux Type "help", "copyright", "credits" or "license" for more information. >>> from multiprocessing import Pool >>> def f(x): ... return x**2 ... >>> with Pool(10) as p: ... print(p.map(f, range(1,10))) [1, 4, 9, 16, 25, 36, 49, 64, 81] So something about having Pool as a context manager means it works - very odd then. BTW - with the exception of the example saying 'don't do this it doesn't work', none of the examples on the page are shown on the command line interpreter; but the first example uses a Pool context manager - which works as above. ---------- _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue34891> _______________________________________
participants (2)
-
Anthony Flury
-
Karthikeyan Singaravelan