1

I don't know if this is possible but I'm trying to open an object from another script by i'ts place on the memory

This is my first script:

from time import sleep
myobj = 'Hi'

# i'm aware that this somehow is the position of the object on memory
myid = id(myobj)

print(myid)
# output: 140196737647120

sleep(3600)

how i could try to open it from a non related script? I tried with:


from ctypes import cast, py_object
jc = cast( 140196737647120 , py_object).value
# output: Segmentation fault (core dumped)

Also if there is some other easier way please suggest

1 Answer 1

1

Virtual memory renders this impossible without altering Python to use shared memory (which is a lot harder to do safely than it sounds).

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for the answer, it did not solve the question but the information was good, at the end i found this gitlab.com/tenzing/shared-array , Thank you.
@VasylYovdiy: It did answer the question, which to your credit acknowledged that the answer might be “you can’t”. I’m glad you found a library you could use; multiprocessing in the standard library also supports (some) such use cases.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.