cpython icon indicating copy to clipboard operation
cpython copied to clipboard

gh-85299: Add note warning about entry point guard for asyncio example

Open slateny opened this issue 3 years ago • 2 comments

#85299

https://docs.python.org/3/library/asyncio-eventloop.html#asyncio.loop.run_in_executor

slateny avatar Jun 03 '22 09:06 slateny

A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated.

Once you have made the requested changes, please leave a comment on this pull request containing the phrase I have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

bedevere-bot avatar Oct 13 '22 17:10 bedevere-bot

Okay, I am beginning to understand the issue. It's due to the process pool example. If I comment out this block of code from the example:

    # 3. Run in a custom process pool:
    with concurrent.futures.ProcessPoolExecutor() as pool:
        result = await loop.run_in_executor(
            pool, cpu_bound)
        print('custom process pool', result)

everything is fine. If I leave that in the run (on macOS) fails spectacularly with a RuntimeError that has many lines of traceback, then a multi-line error message, and then more traceback lines. Adding the __main__ guard makes this go away.

I presume that's one of the many reasons not to use ProcessPoolExecutor. :-(

I propose to rephrase the note to mention the platform and just link to https://docs.python.org/3/library/multiprocessing.html#the-spawn-and-forkserver-start-methods, not to the change note.

gvanrossum avatar Oct 14 '22 16:10 gvanrossum

Thanks @slateny for the PR, and @gvanrossum for merging it 🌮🎉.. I'm working now to backport this PR to: 3.10. 🐍🍒⛏🤖

miss-islington avatar Oct 16 '22 17:10 miss-islington

Thanks @slateny for the PR, and @gvanrossum for merging it 🌮🎉.. I'm working now to backport this PR to: 3.11. 🐍🍒⛏🤖

miss-islington avatar Oct 16 '22 17:10 miss-islington

GH-98334 is a backport of this pull request to the 3.11 branch.

bedevere-bot avatar Oct 16 '22 17:10 bedevere-bot

Let’s see if we can backport this.

gvanrossum avatar Oct 16 '22 17:10 gvanrossum

GH-98335 is a backport of this pull request to the 3.10 branch.

bedevere-bot avatar Oct 16 '22 17:10 bedevere-bot