I am trying to develop an application for the Raspberry Pi3. In fact 2 applications. Application 1 will be a simple gpio read, count the number of times a particular gpio input goes high and log into file . Application 2 will be to show the GPIO status on screen. I want the application 1 to continuously run and log data. That is why I have separated this from the UI based application. Now I want to get the gpio status from application 1 - data will be pin1State, pin1HighCount,pin2State,pin2HighCount. All this will be integers. Application 2 should get data from application 1 and display in a pyqt5 based UI screen. I tried to follow this example IPC shared memory across Python scripts in separate Docker containers But I found that it is a dictionary based data exchange and also it is not continuous or almost real time. The dictionary is first populated and then loaded in the server.py I am not able to find much info on this method elsewhere. I like the local host based socket approach without using files (temporary or otherwise). But I am not able to get continuous data. Also , is it possible to do use a list or even individual integer variables instead of a dictionary. I am worried that by continuously updating (Appending) to the dictionary, it might create a memory overload if the script runs for long durations my code as follows Server.py
from multiprocessing.managers import SyncManager
import multiprocessing
patch_dict = {}
def load_patch_dict():
value = input("Press key to continue \n")
for i in range(0,2000):
patches = 1
patch_dict.update([(i, i)])
print("Patch Print ",i," . ",patch_dict)
#print(patch_dict)
def get_patch_dict():
return patch_dict
class MyManager(SyncManager):
pass
if __name__ == "__main__":
load_patch_dict()
port_num = 5000
MyManager.register("patch_dict", get_patch_dict)
manager = MyManager(("127.0.0.1", port_num), authkey=b"password")
# Set the authkey because it doesn't set properly when we initialize MyManager
multiprocessing.current_process().authkey = b"password"
manager.start()
input("Press any key to kill server".center(50, "-"))
manager.shutdown()
Client.py
rom multiprocessing.managers import SyncManager
import multiprocessing
import sys, time
class MyManager(SyncManager):
pass
# MyManager.register("patch_dict")
if __name__ == "__main__":
port_num = 5000
MyManager.register("patch_dict")
manager = MyManager(("127.0.0.1", port_num), authkey=b"password")
multiprocessing.current_process().authkey = b"password"
manager.connect()
patch_dict = manager.patch_dict()
keys = list(patch_dict.keys())
#print("Keys ", keys)
value = input("Press key to continue \n")
do_loop = True
i=1
for key in keys:
image_patches = manager.patch_dict.get(key)
print("This is ",image_patches)