# CS 450: Python Process Example # version 2014-01-21 7:33 PM # # Create some processes and start them # # Run using python3 Lec03_proc4.py # from multiprocessing import Process def go_proc(): for i in range(5): # Create each process, have it run say_hello(i) # then print child's process id # p = Process(target=say_hello, args=([i])) # (Note list of argument values) p.start() print('started process {}'.format(p.pid)) def say_hello(id): print('hello from child {}'.format(id)) go_proc() # run the main program # Sample output # # started process 1214 # started process 1215 # hello from child 0 # started process 1216 # hello from child 1 # started process 1217 # hello from child 2 # hello from child 3 # started process 1218 # hello from child 4