[issue31556] asyncio.wait_for can cancel futures faster with timeout==0

2017-10-05 Thread Yury Selivanov

Yury Selivanov  added the comment:

Note, that this will not be backported to 3.6, as it behaves in a slightly 
incompatible way.  I consider this patch as an enhancement that makes 
'asyncio.wait_for' semantics easier to reason about and more practical.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue31556] asyncio.wait_for can cancel futures faster with timeout==0

2017-10-05 Thread Yury Selivanov

Change by Yury Selivanov :


--
resolution:  -> fixed
stage: patch review -> resolved
status: open -> closed
type:  -> behavior

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue31556] asyncio.wait_for can cancel futures faster with timeout==0

2017-09-22 Thread Viktor Kovtun

Viktor Kovtun added the comment:

Actually provided example without patch will print 1, which is not expected

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue31556] asyncio.wait_for can cancel futures faster with timeout==0

2017-09-22 Thread Yury Selivanov

Yury Selivanov added the comment:

You're right!  Let's work on the PR then, I've left a review comment.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue31556] asyncio.wait_for can cancel futures faster with timeout==0

2017-09-22 Thread Viktor Kovtun

Viktor Kovtun added the comment:

asyncio.wait_for is coroutine itself, to start executing code, no matter with 
this PR or not it needs to be awaited/yield from

import asyncio

@asyncio.coroutine
def foo():
print(1)

loop = asyncio.get_event_loop()

fut = asyncio.wait_for(foo(), 0)

print('it is not raised yet')

try:
loop.run_until_complete(fut)
except asyncio.TimeoutError:
print('raised here')


will print 
it is not raised yet
raised here

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue31556] asyncio.wait_for can cancel futures faster with timeout==0

2017-09-22 Thread Yury Selivanov

Yury Selivanov added the comment:

I think this is a backwards incompatible change and thus will be rejected.  
Currently there's a guarantee that "wait_for" can throw a TimeoutError *only* 
when when you await it.

   fut = wait_for(something, 0)

   # some important code

   try:
   await fut
   except TimeoutError:
   # do something

With your PR merged, the above asyncio code would be broken, because asyncio 
users can guard with try..except only the await expression.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue31556] asyncio.wait_for can cancel futures faster with timeout==0

2017-09-22 Thread Viktor Kovtun

Viktor Kovtun added the comment:

If coroutine function has some blocking calls before first await/yield from 
statement maybe makes sense do no let them be executed, if timeout equals 0

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue31556] asyncio.wait_for can cancel futures faster with timeout==0

2017-09-22 Thread Yury Selivanov

Yury Selivanov added the comment:

Do you have a use case where this optimization is important?

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue31556] asyncio.wait_for can cancel futures faster with timeout==0

2017-09-22 Thread Viktor Kovtun

Changes by Viktor Kovtun :


--
keywords: +patch
pull_requests: +3687
stage:  -> patch review

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue31556] asyncio.wait_for can cancel futures faster with timeout==0

2017-09-22 Thread Viktor Kovtun

New submission from Viktor Kovtun:

There is no need to create extra future and use loop.call_later to cancel base 
future from asyncio.wait_for when timeout==0. If loop is heavy loaded it can be 
cancelled simnifically later then 0 seconds later.

--
components: asyncio
messages: 302770
nosy: asvetlov, hellysmile, yselivanov
priority: normal
severity: normal
status: open
title: asyncio.wait_for can cancel futures faster with timeout==0
versions: Python 3.6, Python 3.7

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com