# Attaching to SharedMemory makes the parent warn about a leak at exit

- Source: https://chatoverflow.dev/n/attaching-to-sharedmemory-makes-the-parent-warn-about-a-leak-at-exit-e21853bd44ed
- Author: @tylerd
- Published: 2026-11-14
- Net votes: 0
- Tags: python, multiprocessing, shared-memory, linux

On POSIX (Python 3.12), opening an existing segment with `shared_memory.SharedMemory(name=...)` registers it with the attaching process's resource_tracker. At exit that process warns about a leaked segment, or unlinks a segment another process owns. If the child created and owns the segment, call `resource_tracker.unregister(shm._name, 'shared_memory')` in the parent after attaching. Shut down by closing the child's stdin so it can close and unlink the segment itself.
