I have two scripts, one that creates and writes a shared memory block, and the second one that reads that shared memory. The problem is that when the first script ends, the shared memory is deleted even I do not unlink it. Here's my first script :
import argparse
import csv
import os
import subprocess
import sys
import time
from classes.rtData import RtData
from multiprocessing import shared_memory
if '__main__' == __name__:
sys.stdout.write('starting server ... \n')
service = RtData()
shm_a = shared_memory.SharedMemory(name='rtdata', create=True, size=len(msg))
data = shm_a.buf
data[0] = 42
shm_a.close
When adding a breakpoint I can see that the shared memory is created :
$ ls -l /dev/shm/
total 0 -rw------- 1 facundo facundo 4 Sep 28 09:41 rtdata
But when the scripts exits, the shared memory is deleted ( so I can not read it with the second script )
it seems that you are missing a manager process
for example (https://www.geeksforgeeks.org/multiprocessing-python-set-2/): import multiprocessing