start and join
- Python course
- Expert
- Lesson 26/47
- 5 min
Learn process management with start and join.
What are start and join?
.start() sends a Process to run; .join() waits for it to finish. Together they manage the process lifecycle.
After start the process runs in the background. The main program continues immediately. When join is called the main program waits for the process to finish. The order matters: start first, then join. Without join the main program may exit before the process finishes, causing unexpected behavior.
Multiple processes
You create multiple Process objects, start them all with start, then wait with join. This is the basic pattern of parallel work.
For example if you start two processes and join them in order, both run in parallel and the main program does not continue until both finish. The output order may depend on how fast each process completes; for deterministic results you use Queue. But lifecycle management is always the same: all start calls first, then all join calls.
Practice Sequential output with start and join
Import with from multiprocessing import Process. Define a worker function that does print("bitti"). Create a process with Process(target=worker). Call .start() and .join(). Then print "tamam" in the main program.
Starter code
# write the worker function
# create, start and join the process
# then print in the main programSample solution
from multiprocessing import Process
def worker():
print("done")
p = Process(target=worker)
p.start()
p.join()
print("tamam")Expected output
bitti tamam
Questions and answers
Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.
1 Match start/join concepts
| Term | Meaning |
|---|---|
start |
Launches the process |
join |
Waits for completion |
target |
Function |
Process |
Process object |
2 Complete the join call
p.start()
p.____()
p.start()
p.join()
Explanation: join() waits for the process to finish.
3 What happens without join?
from multiprocessing import Process
p = Process(target=func)
p.start()
# no join
print('done')- The main program continues without waiting Correct answer
- The process never starts
- The process runs forever
- It raises an error
Explanation: answer: the main program continues without waiting. join provides the wait.