Skip to content

Commit 31b36cf

Browse files
committed
Add function to cleanup existing SHM
1 parent 1016786 commit 31b36cf

2 files changed

Lines changed: 18 additions & 0 deletions

File tree

example/simple_task.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,10 @@ def _main_shm_autostart():
9393

9494

9595
if __name__ == "__main__":
96+
# Clear any previous SHM if found
97+
pyarraypool.cleanup_shm()
98+
99+
# Run main
96100
_main_classic()
97101
_main_shm_manualmanagement()
98102
_main_shm_autostart()

python/pyarraypool/__init__.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,3 +157,17 @@ def object_pool_context() -> Iterator[None]:
157157
yield
158158
finally:
159159
stop_pool()
160+
161+
162+
def cleanup_shm():
163+
"""Remove previous SHM if any."""
164+
link_path = Path(_CFG_LINK_PATH)
165+
if not link_path.exists():
166+
return
167+
168+
segment_name = link_path.read_text().strip("/")
169+
segment_path = Path("/dev/shm") / segment_name
170+
171+
LOGGER.info("Removing SHM segment: %s", segment_path)
172+
link_path.unlink(missing_ok=True)
173+
segment_path.unlink(missing_ok=True)

0 commit comments

Comments
 (0)