[issue37494] Call asyncio Future in scope

2019-07-03 Thread Andrew Svetlov


Andrew Svetlov  added the comment:

It doesn't.
Loop is executed by asyncio.run() (recommended) or low-level 
loop.run_until_complete() / loop.run_forever() calls.

Please note, this tracker is for working on Python itself, not for teaching 
Python usage.
Please use other resources like forums or stack overflow.

I'm closing the issue as there is no bug here but improper usage example.

--
resolution:  -> not a bug
stage:  -> resolved
status: open -> closed

___
Python tracker 

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



[issue37494] Call asyncio Future in scope

2019-07-03 Thread Fourcade


Fourcade  added the comment:

Here's the file with an example. The get_progress function always outputs 0.

--
Added file: https://bugs.python.org/file48454/test_progress.py

___
Python tracker 

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



[issue37494] Call asyncio Future in scope

2019-07-03 Thread Fourcade


Fourcade  added the comment:

If I add a simple print inside long_task, the print is executed correctly. So 
it seems this code actually runs the loop. 

(I'm on python 3.6.8).

--

___
Python tracker 

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



[issue37494] Call asyncio Future in scope

2019-07-03 Thread Andrew Svetlov


Andrew Svetlov  added the comment:

Your code doesn't run the event loop, only creates it.
What do you expect?

--

___
Python tracker 

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



[issue37494] Call asyncio Future in scope

2019-07-03 Thread Fourcade


New submission from Fourcade :

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 

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