This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: can concurrent.futures len(Executor) return the number of tasks?
Type: enhancement Stage:
Components: Library (Lib) Versions: Python 3.6
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: Pat Riehecky, bquinlan, pitrou
Priority: normal Keywords:

Created on 2015-07-31 19:55 by Pat Riehecky, last changed 2022-04-11 14:58 by admin.

Messages (4)
msg247766 - (view) Author: Pat Riehecky (Pat Riehecky) Date: 2015-07-31 19:55
As a feature request, can the Executor respond to a len() request by showing the number of non-finished/non-canceled items in the pool?

I would like a clean pythonic way of seeing how many items remain to be executed and this seemed the way to go.

psudo-code:

    myvar = list(range(1, 30))

    pool = concurrent.futures.ThreadPoolExecutor(max_workers=2)
    results = pool.map(myfunction, myvar)

    for result in results:
        print("waiting for " + str(len(pool)) + " tasks to finish")
msg247770 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2015-07-31 20:38
I don't think len() is a good idea for this, it's not obvious enough (why the number of tasks and not the number of threads/processes, for example?). Also, len() can make the object evaluate false-y in a boolean context, if len() returns 0.

A dedicated method would probably be ok, though. With the caveat that the return value would always be an approximation of the "actual" value.
msg247773 - (view) Author: Pat Riehecky (Pat Riehecky) Date: 2015-07-31 21:26
works for me
msg341769 - (view) Author: Brian Quinlan (bquinlan) * (Python committer) Date: 2019-05-07 16:18
If we supported this, aren't we promising that we will always materialize the iterator passed to map?

I think that we'd need a really strong use-case for this to be worth-while.
History
Date User Action Args
2022-04-11 14:58:19adminsetgithub: 68955
2019-05-07 16:18:32bquinlansetmessages: + msg341769
2015-07-31 21:26:18Pat Rieheckysetmessages: + msg247773
2015-07-31 20:38:38pitrousetnosy: + bquinlan, pitrou

messages: + msg247770
versions: + Python 3.6, - Python 3.4
2015-07-31 19:55:13Pat Rieheckycreate