Visitar URL original
bpo-44225: Fix bug with asyncio BaseEventLoop.run_forever() by whosmega · Pull Request #26483 · python/cpython · GitHub
The Wayback Machine - https://web.archive.org/web/20221223170404/https://github.com/python/cpython/pull/26483
Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bpo-44225: Fix bug with asyncio BaseEventLoop.run_forever() #26483

Closed
wants to merge 5 commits into from
Closed

bpo-44225: Fix bug with asyncio BaseEventLoop.run_forever() #26483

wants to merge 5 commits into from

Conversation

whosmega
Copy link

@whosmega whosmega commented Jun 2, 2021 •

@the-knights-who-say-ni
Copy link

the-knights-who-say-ni commented Jun 2, 2021

Hello, and thanks for your contribution!

I'm a bot set up to make sure that the project can legally accept this contribution by verifying everyone involved has signed the PSF contributor agreement (CLA).

CLA Missing

Our records indicate the following people have not signed the CLA:

@megahypex

For legal reasons we need all the people listed to sign the CLA before we can look at your contribution. Please follow the steps outlined in the CPython devguide to rectify this issue.

If you have recently signed the CLA, please wait at least one business day
before our records are updated.

You can check yourself to see if the CLA has been received.

Thanks again for the contribution, we look forward to reviewing it!

Copy link
Member

@iritkatriel iritkatriel left a comment

Please add a unit test which is failing without the fix and passing with it.

@bedevere-bot
Copy link

bedevere-bot commented Jun 2, 2021

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.

@whosmega
Copy link
Author

whosmega commented Jun 3, 2021

import asyncio
loop  = asyncio.get_event_loop()
async def coro(x):
    print(x)
    if x < 10:
        asyncio.create_task(coro(x+1))
    else:
        loop.stop()

loop.create_task(coro(0))
loop.stop()
loop.run_forever()

The following code produces the output

0

(replicated on python version 3.11, 3.10 and 3.9)
With the fixes applied, it produces the following output:

0
1
2
3
4
5
6
7
8
9
10

@whosmega
Copy link
Author

whosmega commented Jun 3, 2021

I have made the requested changes; please review again

@bedevere-bot
Copy link

bedevere-bot commented Jun 3, 2021

Thanks for making the requested changes!

@iritkatriel: please review the changes made to this pull request.

@bedevere-bot bedevere-bot requested a review from iritkatriel Jun 3, 2021
@iritkatriel
Copy link
Member

iritkatriel commented Jun 3, 2021

The unit tests for this script are in Lib/test/test_asyncio/test_base_events.py
https://github.com/python/cpython/blob/main/Lib/test/test_asyncio/test_base_events.py
This will need to be added as one of the unit tests there.

This might help: https://devguide.python.org/runtests/

@whosmega
Copy link
Author

whosmega commented Jun 3, 2021 •

I have added a test for this particular bug called test_run_forever_iteration_break in the file Lib/Test/test_asyncio/test_base_events.py, kindly check. @iritkatriel

Thanks, this is now ready for the code owners to review.

@iritkatriel iritkatriel requested review from iritkatriel and removed request for iritkatriel Jun 3, 2021
@github-actions
Copy link

github-actions bot commented Jul 4, 2021

This PR is stale because it has been open for 30 days with no activity.

@github-actions github-actions bot added the stale Stale PR or inactive for long period of time. label Jul 4, 2021
@whosmega whosmega closed this Sep 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting change review stale Stale PR or inactive for long period of time.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants