ukrbublik / shm-typed-array

IPC shared memory for NodeJs. Use as Buffer or TypedArray.
MIT License
71 stars 9 forks source link

shm.get refuses to read shared memory created by python process #23

Closed bantixgithub closed 1 month ago

bantixgithub commented 1 month ago

This is my python script.py:

from multiprocessing import shared_memory
memory = shared_memory.SharedMemory(None, create=True, size=81 + 4)
print(f"PY:    shared_memory_name: {memory.name}")
input() # this hangs the script 

This is my node index.ts:

import shm from "shm-typed-array"
const buf = shm.get(process.argv[2])
log(buf.length)
process.exit(1)

I run this b like this:

python test.py

(copy the key i.e: psm_d464f8bd)

npx tsc && node dist/index.js psm_d464f8bd

This is my output from node:

NODE:  shared_memory_name: psm_d464f8bd
NODE:  0

So buf.length is 0, while it should be 85. shm.get doesn't return null or undefined so it registers that there is some shared memory assigned there, but it refuses to read it... Why?

I tried spawning the node process from python with Popen, because i read something about access only happening when its a child process but same issue. Im on arch btw