将 Python 对象放置在共享内存中

发布于 2024-11-14 05:44:49 字数 598 浏览 3 评论 0原文

是否有一个 Python 模块可以让我将重要用户类的实例放入共享内存中?

我的意思是直接在共享内存中分配,而不是在其中进行酸洗。

multiprocessing.Valuemultiprocessing.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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

音盲 2024-11-21 05:44:49

这有点艰难。我能想到的最好的解决方案是腌制你的对象并使用 c_char_pmultiprocessing.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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文