Placing Python objects in shared memory

﹥>﹥吖頭↗ 提交于 2019-12-03 12:45:24

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/6270849/placing-python-objects-in-shared-memory

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!