如何获取内存中的对象? python 指针
How to get an object in memory ? python pointers
我不知道这是否可行,但我正在尝试通过我放在内存中的另一个脚本打开一个对象
这是我的第一个脚本:
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)
我如何尝试从不相关的脚本打开它?
我试过:
from ctypes import cast, py_object
jc = cast( 140196737647120 , py_object).value
# output: Segmentation fault (core dumped)
另外如果有其他更简单的方法请推荐
如果不更改 Python 以使用 共享内存,虚拟内存使这成为不可能(这比听起来要安全得多)。
我不知道这是否可行,但我正在尝试通过我放在内存中的另一个脚本打开一个对象
这是我的第一个脚本:
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)
我如何尝试从不相关的脚本打开它? 我试过:
from ctypes import cast, py_object
jc = cast( 140196737647120 , py_object).value
# output: Segmentation fault (core dumped)
另外如果有其他更简单的方法请推荐
如果不更改 Python 以使用 共享内存,虚拟内存使这成为不可能(这比听起来要安全得多)。