Skip to content

Instantly share code, notes, and snippets.

@mjm522
Last active October 6, 2020 10:32
Show Gist options
  • Save mjm522/aff694e48383cb743f8a599ab358ef1c to your computer and use it in GitHub Desktop.
Save mjm522/aff694e48383cb743f8a599ab358ef1c to your computer and use it in GitHub Desktop.
Inter process communication using numpy.nmap
import numpy as np
from multiprocessing import Process
def worker(array_file):
count = 0
temp = np.zeros(6)
while True:
count += 1
temp[-1] = count
array_file[:] = temp[:]
filename = "/tmp/array_file.arr"
file = np.memmap(filename, mode="w+", dtype='float32', shape=(6,))
proc = Process(target=worker, args=(file,))
proc.start()
while True:
read_value = np.memmap(filename, dtype='float32', mode='r', shape=(6,))
print("Value read is ", read_value)
proc.join()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment