Python Forum
Parallel Processing in Python with Robot
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Parallel Processing in Python with Robot
#6
A simple program (with messy output) to start a counter (robot moving) while getting info from the keyboard. See Doug Hellmann's Python Module of the Week, "Managing Shared State" at https://pymotw.com/3/multiprocessing/communication.html You create a Manager Dictionary, pass it to the process per the example at PyMOTW, and then use it like a regular dictionary from within or outside of the process.
import time
from multiprocessing import Process

def another_process(spaces):
        ctr=1

        print("spaces", len(spaces))
        while True:
            print(spaces, ctr)
            ctr += 1
            time.sleep(1)

if __name__ == "__main__":
    spaces=""
    ## start with one running process
    processes_list=[]
    p=Process(target=another_process, args=(spaces,))
    p.start()
    processes_list.append(p)

    while True:
      option=input('''"s" to start another process
"q" to quit this program ''')
      option=option.lower()
      if "s" == option:
        spaces += "     "
        p=Process(target=another_process, args=(spaces,))
        p.start()
        processes_list.append(p)
      elif "q" == option:
        for p in processes_list:
            p.terminate()
            p.join()
        break 
Reply


Messages In This Thread
RE: Parallel Processing in Python with Robot - by woooee - Apr-06-2018, 01:21 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Parallel processing - AttributeError: Can't get attribute 'sktimekmeans' Mohana1983 1 803 Jun-22-2023, 02:33 AM
Last Post: woooee
  parallel loop python caro 4 1,900 Jun-16-2022, 08:46 PM
Last Post: woooee
  The Wall-E Robot Argentum 1 1,460 Apr-03-2022, 03:01 PM
Last Post: sastonrobert
  mysql.connector.errors.ProgrammingError: Failed processing format-parameters; Python ilknurg 3 5,734 Jan-18-2022, 06:25 PM
Last Post: ilknurg
  SimpleHTTPRequestHandler ( verses ) Files Python Processing JohnnyCoffee 0 1,809 Apr-29-2021, 02:47 AM
Last Post: JohnnyCoffee
  Real Time Audio Processing with Python Sound-Device not working Slartybartfast 2 4,054 Mar-14-2021, 07:20 PM
Last Post: Slartybartfast
  DarkPaw Robot code Tyrelex78 3 2,184 Nov-27-2020, 12:06 AM
Last Post: Tyrelex78
  Image Processing in Python JoeDainton123 1 24,409 Oct-05-2020, 12:08 AM
Last Post: Larz60+
  Matlab to Python -- Parallel Computing zistambo 1 2,004 Jun-10-2020, 04:59 PM
Last Post: pyzyx3qwerty
  Use dynamic variable from parallel running python script Sicksym 0 1,891 May-15-2020, 02:52 PM
Last Post: Sicksym

Forum Jump:

User Panel Messages

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