79276864

Date: 2024-12-12 23:31:15
Score: 1
Natty:
Report link

This question is old but still referenced by Google. In Python 3 the multiprocessing module allows data to be stored in a memory map between parent and child processes using Value, Array, or more in general multiprocessing.sharedctypes. These are very easy to use:

import multiprocessing
counter = multiprocessing.Value('i', 0)
with counter.get_lock():
    counter.value += 1

And since Python 3.8, there is also 'true' shared memory (across any process and surviving the creator): https://docs.python.org/3/library/multiprocessing.shared_memory.html

This StackOverflow reply by Rboreal_Frippery has a nice example

Reasons:
  • Blacklisted phrase (1): StackOverflow
  • Has code block (-0.5):
  • Low reputation (0.5):
Posted by: marco