from multiprocessing import Process def say_hello(name='world'): print "Hello, %s" % name p = Process(target=say_hello) p.start() p.join() # Tells the program to wait until p has finished it's job before exiting
Here is what the above code is Doing:
1. We create a function that prints a greeting.
2. We create a Process object and pass it the function we want to run.
3. We call the start method on the Process object. This tells the operating system to create a new process and run the function we passed it.
4. We call the join method on the Process object. This tells the program to wait until the process we created has finished running before exiting.