Last active
October 6, 2020 10:32
-
-
Save mjm522/aff694e48383cb743f8a599ab358ef1c to your computer and use it in GitHub Desktop.
Inter process communication using numpy.nmap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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