将 Python 对象放置在共享内存中
是否有一个 Python 模块可以让我将重要用户类的实例放入共享内存中?
我的意思是直接在共享内存中分配,而不是在其中进行酸洗。
multiprocessing.Value
和 multiprocessing.Array
不适用于我的用例,因为它们似乎只支持原始类型及其数组。
到目前为止我唯一发现的是 POSH,但八年来它没有改变年。这表明它要么超级稳定,要么已经过时。在我投入时间尝试让它发挥作用之前,我想知道是否还有我尚未发现的替代方案。
我只需要这个就可以在 Linux 上工作。
Is there a Python module that would enable me to place instances of non-trivial user classes into shared memory?
By that I mean allocating directly in shared memory as opposed to pickling into and out of it.
multiprocessing.Value
and multiprocessing.Array
wouldn't work for my use case as they only seem to support primitive types and arrays thereof.
The only thing I've found so far is POSH, but it hasn't changed in eight years. This suggests that it's either super-stable or is out of date. Before I invest time in trying to get it work, I'd like to know if there are alternatives I haven't discovered yet.
I only need this to work on Linux.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这有点艰难。我能想到的最好的解决方案是腌制你的对象并使用 c_char_p与 multiprocessing.sharedctypes。您仍然必须确保没有空字节进入 c_char_p,方法是转义它们或转换为十六进制。
再想一想,也许你应该选择 POSH。
That's kind of a tough one. The best solution I can think of is pickling your objects and using a c_char_p with multiprocessing.sharedctypes. You'd still have to make sure no null bytes got into the c_char_p, either by escaping them or converting to hex.
On second thought, maybe you should go with POSH.