Feature or enhancement
Proposal:
Currently, the multiprocessing.heap module validates requested memory sizes in two different places:
Heap.malloc()
BufferWrapper.__init__()
Both duplicate the same logic:
if size < 0:
raise ValueError("Size {0:n} out of range".format(size))
if sys.maxsize <= size:
raise OverflowError("Size {0:n} too large".format(size))
Proposed Change
Move this logic into a private static method (Heap._validate_size).
Benefits
- Removes duplication and ensures consistency.
- Improves maintainability (future changes affect only one place).
- Binds
sys.maxsize at definition time (_maxsize=sys.maxsize) to avoid repeated global lookups.
Impact
- No behavior changes. This change does not alter functionality or the external API of multiprocessing. It only removes duplication and ensures future modifications to size validation remain consistent.
- Existing
multiprocessing tests already cover these code paths.
Has this already been discussed elsewhere?
This is a minor feature, which does not need previous discussion elsewhere
Links to previous discussion of this feature:
No response
Linked PRs
Feature or enhancement
Proposal:
Currently, the
multiprocessing.heapmodule validates requested memory sizes in two different places:Heap.malloc()BufferWrapper.__init__()Both duplicate the same logic:
Proposed Change
Move this logic into a private static method (Heap._validate_size).
Benefits
sys.maxsizeat definition time (_maxsize=sys.maxsize) to avoid repeated global lookups.Impact
multiprocessingtests already cover these code paths.Has this already been discussed elsewhere?
This is a minor feature, which does not need previous discussion elsewhere
Links to previous discussion of this feature:
No response
Linked PRs