final concurrency examples
This commit is contained in:
19
futures/future_yield2.py
Normal file
19
futures/future_yield2.py
Normal file
@@ -0,0 +1,19 @@
|
||||
@asyncio.coroutine
|
||||
def a(future):
|
||||
print('a, future:', future, hex(id(future)))
|
||||
res = yield from future
|
||||
return res
|
||||
|
||||
def b():
|
||||
future = asyncio.Future()
|
||||
coro = a(future)
|
||||
prime_result = next(coro)
|
||||
print('b, prime_result:', prime_result, hex(id(future)))
|
||||
|
||||
loop = asyncio.get_event_loop()
|
||||
future = asyncio.Future()
|
||||
print('future:', future, hex(id(future)))
|
||||
tasks = [asyncio.async(a(future))]
|
||||
|
||||
res = loop.run_until_complete(b())
|
||||
|
||||
Reference in New Issue
Block a user