[issue24578] [RFE] Add asyncio.wait_for_result API

2015-07-07 Thread Nick Coghlan

Nick Coghlan added the comment:

It occurs to me that given both this API and the call_async() API now 
proposed in issue 24571, otherwise synchronous code can do things like:

futureB = asyncio.call_async(slow_io_bound_operation)
futureC = asyncio.call_async(another_slow_io_bound_operation)
a = calculateA()
b = asyncio.wait_for_result(futureB)
c = asyncio.wait_for_result(futureC)

Which still reads well when combined with await:

b = await asyncio.call_async(blocking_operation)

--

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



[issue24578] [RFE] Add asyncio.wait_for_result API

2015-07-07 Thread Guido van Rossum

Guido van Rossum added the comment:

Maybe the two issues should be merged so the two proposals can be considered 
together. I'm -0 on both, because each of these is really just one line of code 
and it seems they both encourage mindless copy-pasting that just saddens me 
(similar to Python scripts I sometimes see that are just a series of shell 
invocations using subprocess.getoutput() or similar, including calls to rm or 
echo).

--

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



[issue24578] [RFE] Add asyncio.wait_for_result API

2015-07-07 Thread Nick Coghlan

Nick Coghlan added the comment:

As Guido suggested, merging back into issue 24571

--
resolution:  - duplicate
status: open - closed
superseder:  - [RFE] Add asyncio.call_async API

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



[issue24578] [RFE] Add asyncio.wait_for_result API

2015-07-06 Thread Sven R. Kunze

New submission from Sven R. Kunze:

In order to complement http://bugs.python.org/issue24571, this is another 
high-level convenience API for asyncio to treat an awaitable like a usual 
subroutine (credits go to Nick Coghlan):

# Call awaitable from synchronous code
def wait_for_result(awaitable):
Usage: result = asyncio.wait_for_result(awaitable)
return 
asyncio.get_event_loop().run_until_complete(awaitable.__await__())

It may not be that conceptually dense, however, I feel for projects 
transitioning from the classical subroutine world to the asyncio world, this 
functionality might prove useful to bridge both worlds seamlessly when 
necessary.

--
components: asyncio
messages: 246373
nosy: gvanrossum, haypo, srkunze, yselivanov
priority: normal
severity: normal
status: open
title: [RFE] Add asyncio.wait_for_result API
versions: Python 3.5, Python 3.6

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



[issue24578] [RFE] Add asyncio.wait_for_result API

2015-07-06 Thread Sven R. Kunze

Changes by Sven R. Kunze srku...@mail.de:


--
nosy: +giampaolo.rodola, ncoghlan, pitrou -srkunze
type:  - enhancement

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



[issue24578] [RFE] Add asyncio.wait_for_result API

2015-07-06 Thread Sven R. Kunze

Changes by Sven R. Kunze srku...@mail.de:


--
nosy: +srkunze

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



[issue24578] [RFE] Add asyncio.wait_for_result API

2015-07-06 Thread Martin Panter

Martin Panter added the comment:

I don’t think you need the __await__() call. Just do 
loop.run_until_complete(awaitable).

I understand “asyncio” doesn’t support recursive calls into the same event loop 
on purpose; see Issue 22239. So this code would only be useful from outside of 
the event loop, or if more than one event loop was in use.

--
nosy: +vadmium

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