Clean up multiprocessing pools on failure#208
Merged
Conversation
Ensure bagit-python reliably cleans up multiprocessing pools when parallel manifest generation or validation fails with processes > 1. Successful make_bag() calls already cleaned up correctly through the normal graceful pool path. The gap was failures inside Pool.map(): worker exceptions skipped close() and join(), allowing BagIt child processes to remain alive after the caller received the error. In long-running services, those leftover children can later become orphaned or defunct when the owning worker exits. This follows up on c451b24 ("Wait for validation Pool to finish"), the validation-pool cleanup work Douglas and I did, by extending the same reliability expectation to failure paths.
5 tasks
acdha
reviewed
Jun 18, 2026
| else: | ||
| pool = multiprocessing.Pool( | ||
| processes if processes else None, initializer=worker_init | ||
| hash_results = _multiprocessing_pool_map( |
Member
There was a problem hiding this comment.
I was wondering whether we might want to refactor this to avoid buffering everything in memory (i.e. using Pool.imap so it could yield from in the utility function but I don't think it's very common that people are using this in a way where they need to worry about total RAM or can meaningfully process the results before they're all ready.
acdha
approved these changes
Jun 18, 2026
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Ensure bagit-python reliably cleans up multiprocessing pools when parallel manifest generation or validation fails with processes > 1.
Successful make_bag() calls already cleaned up correctly through the normal graceful pool path. The gap was failures inside Pool.map(): worker exceptions skipped close() and join(), allowing BagIt child processes to remain alive after the caller received the error. In long-running services, those leftover children can later become orphaned or defunct when the owning worker exits.
This follows up on c451b24 ("Wait for validation Pool to finish"), the validation-pool cleanup work Douglas and I did, by extending the same reliability expectation to failure paths.