[issue37494] Call asyncio Future in scope
Fourcade
report at bugs.python.org
Wed Jul 3 11:53:59 EDT 2019
New submission from Fourcade <robinf95 at yahoo.fr>:
I'm trying to get the progession of my asyncIO Futures. For some reason, I can't get value updates inside any other scope.
For example:
```
import concurrent.futures
import time
import asyncio
import random
def get_progress(futures):
return sum([f.done() for f in futures])
def long_task(t):
time.sleep(1.5)
return t
loop = asyncio.get_event_loop()
executor = concurrent.futures.ProcessPoolExecutor(max_workers=4)
inputs = ['a', 'b', 'c', 'd', 'e', 'f', 'g']
futures_ = [loop.run_in_executor(executor, long_task, i) for i in inputs]
for i in range(5):
time.sleep(1)
print(get_progress(futures_))
```
It prints only 0. However, if I run this inside a terminal and call get_progress(futures_) it prints 7 as expected.
Am I missing something here ?
----------
components: asyncio
messages: 347232
nosy: RobinFrcd, asvetlov, yselivanov
priority: normal
severity: normal
status: open
title: Call asyncio Future in scope
type: behavior
versions: Python 3.6
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue37494>
_______________________________________
More information about the Python-bugs-list
mailing list