You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Pool.imap(buffersize=...) silently drops results after close() #158675
When buffersize is passed to Pool.imap() or Pool.imap_unordered(), calling close() before the iterator is exhausted makes the iterator stop early. No exception is raised. The items that were not submitted to the workers yet are dropped.
Without buffersize, the same code returns all results.
ThreadPool and imap_unordered() are affected in the same way.
Expected:close() is documented as preventing new tasks from being submitted. Items of an imap() call that was already made should still be processed, as they are without buffersize.
Cause: This comes from the fix for gh-155477 (gh-155478). close() now releases the buffersize semaphores, and _guarded_task_generation() stops as soon as it sees self._state != RUN. The task handler then treats the generator as exhausted and calls set_length(), so the iterator ends with a normal StopIteration.
The test added in gh-155478 only checks that close() + join() does not hang. It does not check the number of results.
Proposed fix: Keep throttling after close(), and only stop throttling in join(), where the remaining items are submitted without waiting for the consumer. That keeps gh-155477 fixed and does not lose results.
I would like to work on this. I have a patch with tests and will open a PR.
buffersize was added in gh-64192 and is new in Python 3.16, so no released version is affected.
changed the title [-]Title: Pool.imap(buffersize=...) silently drops results after close()[/-][+]`Pool.imap(buffersize=...)` silently drops results after close()[/+]on Oct 3, 2026
Activity
[-]Title: Pool.imap(buffersize=...) silently drops results after close()[/-][+]`Pool.imap(buffersize=...)` silently drops results after close()[/+]