python / python/cpython

`concurrent.futures.Executor.map` temporarily exceeds its `buffersize` while collecting the next result

Open
#131,466 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

stdlib topic-multiprocessing type-bug
Dominant language
Python
Stars
77.2k
Forks
35.9k
PR merge metrics
PR metrics pending

Description

Bug report

Bug description:

Potential follow up after the merge of #125663 (introduce buffersize param in Executor.map).

"Bug": concurrent.futures.Executor.map temporarily exceeds its buffersize while collecting the next result:

Let's define:

results: Iterator = executor.map(fn, iterable, buffersize=buffersize)

What happens when calling next(results):

  1. fetch the next arg from interable and put a task for fn(arg) in the buffer
  2. wait for next result to be available
  3. yield the collected result

So during step 2. the buffer's size is actually buffersize + 1.

If we want a strict guarantee that there is at most buffersize concurrent tasks even during a next, we have to swap step 1. and step 2.

CPython versions tested on:

CPython main branch

Operating systems tested on:

No response

Linked PRs
  • gh-131467

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at concurrent.futures.Executor.map and review the behavior described around collecting the next result. Check linked PR gh-131467 to understand the work already underway. Done means ensuring the buffer never temporarily exceeds the requested buffersize while next(results) waits for a result.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.