title: Using Shared Memory to read and write a dict in python
body: <p>I came across this awesome library which supports writing and reading from a shared memory in IPC <a href="https://docs.python.org/3/library/multiprocessing.shared_memory.html" rel="nofollow noreferrer">https://docs.python.org/3/library/multiprocessing.shared_memory.html</a>.</p>
  <p>I am trying to store this info in dictionary and use it. I am able to create a dict on shared space but am unsure how to load those values.</p>
  <pre><code># process1.py
  def write_in_memory()
      shm_a = shared_memory.SharedMemory(name='test', create=True, size=1000)
      print(type(shm_a.buf))
      buffer = shm_a.buf
      print(id(buffer))
      buffer = {
          &quot;CLEAN_DATA&quot;: True,
          &quot;STORE_PATH&quot;: &quot;/tmp&quot;
      }
      shm_a.close()
  write_in_memory()
  </code></pre>
  <p>Retrieving info</p>
  <pre><code>def retrive()
      shm_b = shared_memory.SharedMemory('test')
      print(shm_b)
      buffer = shm_b.buf
      print(buffer)
      print(id(buffer))
      try:
          import json
          temp = json.load(buffer)
          print(temp)
      except Exception as e:
          print(f&quot;Exception as {e}&quot;)
      shm_b.close()
      shm_b.unlink()
  retrive()
  </code></pre>
  <p>Run bot process1 and data is stored in shared space. I have tried to load these value back in python from byte but I feel I am not doing the right thing using explicit conversion using <code>dict</code> or <code>json</code>. Example on the site doesn't show using dict. Any one know what is right thing to do.</p>