Hi folks!
I am wondering why my first example of ThreadPoolExecutor(max_workers=10).map(fn, iterable, buffersize=20) returns only 20 mapped items of 100. Using CPython 3.14.0.
Looking at the implementation of map() there is some weakref wizardry, is the reason for returning a truncated iterable the executor being garbage collected by the time the the buffer needs to be appended to? https://github.com/python/cpython/blob/a005835f699b5ba44beb8c856db1f62454522e1e/Lib/concurrent/futures/\_base.py#L633
Is this a CPython bug perhaps? Or expected behavior? Or am I holding it wrong?
import concurrent.futures
def get_results():
ints = range(100)
with concurrent.futures.ThreadPoolExecutor(max_workers=10) as executor:
return executor.map(str, ints, buffersize=20)
print(len(list(get_results()))) # -> 20 (???)
def get_results_without_buffersize():
ints = range(100)
with concurrent.futures.ThreadPoolExecutor(max_workers=10) as executor:
return executor.map(str, ints)
print(len(list(get_results_without_buffersize()))) # -> 100
def get_results_2():
ints = range(100)
with concurrent.futures.ThreadPoolExecutor(max_workers=10) as executor:
yield from executor.map(str, ints, buffersize=20)
print(len(list(get_results_2()))) # -> 100
def get_results_3():
ints = range(100)
with concurrent.futures.ThreadPoolExecutor(max_workers=10) as executor:
print(len(list(executor.map(str, ints, buffersize=20))))
get_results_3() # -> 100