Python Forum
help with multiprocess concept
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
help with multiprocess concept
#1
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?
Reply
#2
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.
Reply
#3
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
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How we prune Alphabeta Tree Node Using BST concept Anldra12 4 2,363 May-18-2021, 09:17 AM
Last Post: Anldra12
  multiprocess hang when certain number is used in the program esphi 7 3,115 Nov-06-2020, 03:49 PM
Last Post: esphi
  prometheus in multiprocess code georgelza 4 3,871 Jan-21-2020, 05:13 PM
Last Post: georgelza
  Multiprocess not writing to file DreamingInsanity 4 7,842 Dec-07-2019, 03:10 PM
Last Post: DreamingInsanity
  Understanding the concept ( Modules , imports ) erfanakbari1 1 2,140 Nov-25-2019, 01:59 AM
Last Post: Larz60+
  Understand for range concept RavCOder 4 2,737 Oct-29-2019, 02:26 PM
Last Post: newbieAuggie2019
  Recursion concept Truman 8 8,582 Oct-06-2018, 07:48 AM
Last Post: Larz60+
  Concept of batch files Truman 2 2,800 Jul-23-2018, 09:02 PM
Last Post: Truman
  example of multiprocess piping Skaperen 4 5,963 Dec-02-2016, 12:55 PM
Last Post: Larz60+
  multiprocess passing multiple arguments double asterisk pic8690 1 5,225 Oct-23-2016, 08:51 AM
Last Post: Skaperen

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020