Let's perform the following steps:
- 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)
- 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)
- 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()