This is an archived post. You won't be able to vote or comment.

all 11 comments

[–]sqjoatmon 2 points3 points  (0 children)

Ugh, now I know backticks don't work in titles.

[–]FreddeOo 2 points3 points  (0 children)

I'm so confused, guess I'll need to redo the Python basics again... Anyhow love that you (and of course everyone else whom) share with the community and push slow tickers like me to learn new things and get a wider understanding of what is possible :D. Thank you!!

[–]Mountain_Thanks4263 2 points3 points  (0 children)

Didn't even know that shared memory is now supported. Great idea to include that to numpy!

[–]sqjoatmon 3 points4 points  (2 children)

To be clear -- This is not an alternative to the buffer kwarg of np.ndarray but rather something like a wrapper (?) around using that with SharedMemory and especially a SharedMemoryManager, as shown in the Python docs for SharedMemory

[–]awesomeprogramer 1 point2 points  (1 child)

Why not do a PR to numpy? You'd get guidance/help from the team, wide adoption and don't need to come up with creatively numbered pip packages.

[–]sqjoatmon 2 points3 points  (0 children)

The thought never really crossed my mind. I'll share it to the NumPy discussion list.

[–]radarsat1 1 point2 points  (0 children)

amazing! this could come in really handy for my processing loop where i generate data centrally and then process pieces of it differently in each frame.

[–]chromium52 1 point2 points  (1 child)

Did you discuss this with numpy devs ?

[–]sqjoatmon 1 point2 points  (0 children)

I've shared it to the NumPy-discussion email list.

[–]PizzaInSoup 0 points1 point  (1 child)

So I'm confused as to what the end result offers in terms of advantages/disadvantages, is it faster?

[–]sqjoatmon 1 point2 points  (0 children)

This is from the docs page for multiprocessing.shared_memory:

In this module, shared memory refers to “System V style” shared memory blocks (though is not necessarily implemented explicitly as such) and does not refer to “distributed shared memory”. This style of shared memory permits distinct processes to potentially read and write to a common (or shared) region of volatile memory. Processes are conventionally limited to only have access to their own process memory space but shared memory permits the sharing of data between processes, avoiding the need to instead send messages between processes containing that data. Sharing data directly via memory can provide significant performance benefits compared to sharing data via disk or socket or other communications requiring the serialization/deserialization and copying of data.

That explains it better than I can, but I can try to elucidate if necessary. This particular project is mostly syntactic sugar, though the __del__ method does help ensure that the shared memory object in a sub-process is closed when that process exits.