import torch | |
def cleanup_shared_memory(): | |
import os | |
import glob | |
shm_files = glob.glob('/dev/shm/torch_*') | |
for shm_file in shm_files: | |
try: | |
os.remove(shm_file) | |
except OSError as e: | |
print(f"Error removing shared memory file {shm_file}: {e}") | |
# 在主程序开始或结束时调用 | |
cleanup_shared_memory() | |