bpo-31556: asyncio.wait_for can cancel futures faster with timeout <= 0#3703
Conversation
|
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! |
| if timeout is None: | ||
| return (yield from fut) | ||
|
|
||
| if timeout == 0: |
There was a problem hiding this comment.
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 | |||
There was a problem hiding this comment.
Update the NEWS entry to reflect the '<=' change.
| fut = self.new_task(loop, foo()) | ||
|
|
||
| with self.assertRaises(asyncio.TimeoutError): | ||
| loop.run_until_complete(asyncio.wait_for(fut, 0, loop=loop)) |
There was a problem hiding this comment.
Would be great if you cover both timeout=0 and timeout=-1 with self.subTest.
|
LGTM. Please sign the CLA and I can merge this. |
|
CLA was signed |
|
|
||
| if timeout <= 0: | ||
| fut = ensure_future(fut, loop=loop) | ||
| fut.cancel() |
There was a problem hiding this comment.
Can you verify that the new code works the same way as the current asyncio code when fut is an already completed Future.
|
I think https://github.com/hellysmile/cpython/blob/9326df1bf94d781e3bf7d8b3140e6e3a405237b1/Lib/test/test_asyncio/test_tasks.py#L710 should be |
|
If future is created outside |
|
Looks good. |
|
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? |
|
There's no |
|
@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. |
|
@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. |
|
Python 3.7.0 alpha 2 comes 2017-10-16, is there any chance to include this patch to the upcoming alpha release? |
|
Merged. Thanks @hellysmile! |
|
@1st1 Thank you! |
https://bugs.python.org/issue31556