How to do it...

Let's perform the following steps:

  1. The target function for both the processes is the myFunc function. It outputs the process name by evaluating the multiprocessing.current_process().name method:
import multiprocessing
import time

def myFunc():
name = multiprocessing.current_process().name
print ("Starting process name = %s " %name)
time.sleep(3)
print ("Exiting process name = %s " %name)
  1. Then, we create process_with_name simply by instantiating the name parameter and process_with_default_name:
if __name__ == '__main__':
process_with_name = multiprocessing.Process
(name='myFunc process',
target=myFunc)

process_with_default_name = multiprocessing.Process
(target=myFunc)
  1. Finally, the processes are started and then joined:
    process_with_name.start()
process_with_default_name.start()
process_with_name.join()
process_with_default_name.join()
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.21.76.0