It seems SharedMemory only supports the flat name, does anyone know why or any ref? I have searched on the internet for quite a long time, but didn't find any relative..
from multiprocessing import shared_memory
shm = shared_memory.SharedMemory(name='test_dir/test_name', size=16, create=True)
Got
Invalid argument: '/test_dir/test_name'
This is not a problem on macOS and probably not an issue on any Unix type platform. Better to not use a name at all. You can acquire the generated name after instantiation of the segment.
Are you using Windows? As a guess, Windows creates a file based on the name and if that's the case you can imagine why a directory separator might cause a problem.
Better (in my opinion) to allow the shared memory segment reference (its name) be generated for you. You can then acquire the generated name and pass that to other parts of your code (or, indeed, other processes) that want to attach to the segment you've created.
Here's a rather convoluted "Hello world" program to demonstrate this strategy: