help with multiprocess concept - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: help with multiprocess concept (/thread-20414.html) |
help with multiprocess concept - kiyoshi7 - Aug-09-2019 Hi im trying to write a module that communicates with a ucontroller via pyserial, plots data if needed. The general outline of what I want to do is in this Image.. but I`m having a hard time understanding how to get different processes to interact. for example in the pyseral module there are functions how can i call these functions to different processes? RE: help with multiprocess concept - woooee - Aug-09-2019 If you are using Tkinter to plot the data, then multiprocessing is not necessary. You use the after() function to call a function periodically that gets the info from pyserial and plots the data. RE: help with multiprocess concept - kiyoshi7 - Aug-10-2019 thanks, but I'm not planning on using tkinter( i kind of hated using it) i'm sticking to just text based commands and a python script. also plotting may or may not be done, since it would have to depend on what is being called. Also the pyserial part has priority so i dont want anything to slow it down. here is the solution found on stackoverflow from the user Carcigenicate from operator import methodcaller class Spawn: def __init__(self, _number, _max): self._number = _number self._max = _max # Don't call update here def request(self, x): print("{} was requested.".format(x)) def update(self): while True: print("Spawned {} of {}".format(self._number, self._max)) sleep(2) if __name__ == '__main__': spawn = Spawn(1, 1) # Create the object as normal p = multiprocessing.Process(target=methodcaller("update"), args=(spawn,)) # Run the loop in the process p.start() spawn.request(2) # Now you can reference the "spawn" object to do whatever you like |