Skip to content

bpo-31556: asyncio.wait_for can cancel futures faster with timeout <= 0#3703

Merged
1st1 merged 7 commits into
python:masterfrom
hellysmile:wait_for_0
Oct 5, 2017
Merged

bpo-31556: asyncio.wait_for can cancel futures faster with timeout <= 0#3703
1st1 merged 7 commits into
python:masterfrom
hellysmile:wait_for_0

Conversation

@hellysmile

@hellysmile hellysmile commented Sep 22, 2017

Copy link
Copy Markdown
Contributor

@hellysmile
hellysmile requested a review from 1st1 as a code owner September 22, 2017 20:51
@the-knights-who-say-ni

Copy link
Copy Markdown

Hello, and thanks for your contribution!

I'm a bot set up to make sure that the project can legally accept your contribution by verifying you have signed the PSF contributor agreement (CLA).

Unfortunately our records indicate you have not signed the CLA. For legal reasons we need you to sign this before we can look at your contribution. Please follow the steps outlined in the CPython devguide to rectify this issue.

Thanks again to your contribution and we look forward to looking at it!

Comment thread Lib/asyncio/tasks.py Outdated
if timeout is None:
return (yield from fut)

if timeout == 0:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You probably want to put timeout <= 0 here to enable this behaviour for timeouts that were computed.

@@ -0,0 +1 @@
Cancel asyncio.wait_for future faster if timeout==0

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update the NEWS entry to reflect the '<=' change.

Comment thread Lib/test/test_asyncio/test_tasks.py Outdated
fut = self.new_task(loop, foo())

with self.assertRaises(asyncio.TimeoutError):
loop.run_until_complete(asyncio.wait_for(fut, 0, loop=loop))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be great if you cover both timeout=0 and timeout=-1 with self.subTest.

@hellysmile hellysmile changed the title bpo-31556: asyncio.wait_for can cancel futures faster with timeout==0 bpo-31556: asyncio.wait_for can cancel futures faster with timeout <= 0 Sep 22, 2017
@1st1

1st1 commented Sep 22, 2017

Copy link
Copy Markdown
Member

LGTM. Please sign the CLA and I can merge this.

@hellysmile

Copy link
Copy Markdown
Contributor Author

CLA was signed

Comment thread Lib/asyncio/tasks.py

if timeout <= 0:
fut = ensure_future(fut, loop=loop)
fut.cancel()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you verify that the new code works the same way as the current asyncio code when fut is an already completed Future.

@hellysmile

Copy link
Copy Markdown
Contributor Author

I think https://github.com/hellysmile/cpython/blob/9326df1bf94d781e3bf7d8b3140e6e3a405237b1/Lib/test/test_asyncio/test_tasks.py#L710 should be self.assertIsNone(foo_running) , but it fails give me a moment to check what is going on there

@hellysmile

Copy link
Copy Markdown
Contributor Author

If future is created outside wait_for it has time for executing blocking code, but if coroutine object passed and future created inside wait_for is not started as expected, test for this case was added

@asvetlov

Copy link
Copy Markdown
Contributor

Looks good.

@hellysmile

Copy link
Copy Markdown
Contributor Author

It seems @the-knights-who-say-ni can not find my CLA, no green badge for 2 days. Is it makes any sense to try to sign it one more time?

@1st1

1st1 commented Sep 25, 2017

Copy link
Copy Markdown
Member

There's no * mark near your name on bugs.python.org. Can you ping PSF?

@ncoghlan

Copy link
Copy Markdown
Contributor

@1st1 Note that the signed CLAs are reviewed & recorded by PSF staff during US business hours, so it isn't unusual for signatures submitted on a Friday not to be noted until the following Monday. It's only when the next US business day has been and gone without the CLA signature being noted that the question may need to be escalated.

@1st1

1st1 commented Sep 26, 2017

Copy link
Copy Markdown
Member

@ncoghlan Oh, I didn't realize that I was suggesting to ping the PSF on Monday morning.. Sorry about that.

@hellysmile I'll need a bit more time to play with the PR before merging it, but so far I expect to merge it as is.

@hellysmile

Copy link
Copy Markdown
Contributor Author

Python 3.7.0 alpha 2 comes 2017-10-16, is there any chance to include this patch to the upcoming alpha release?

@1st1
1st1 merged commit 4d07189 into python:master Oct 5, 2017
@1st1

1st1 commented Oct 5, 2017

Copy link
Copy Markdown
Member

Merged. Thanks @hellysmile!

@hellysmile

Copy link
Copy Markdown
Contributor Author

@1st1 Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants