Threads vs Processes

Process

A completely separate restaurant kitchen.

  • Has its own stove, utensils, ingredients, chef
  • Can’t access another kitchen’s ingredients
  • If it caches fire, only that kitchen burns down
  • More expensive to setup and tear down

Thread

Multiple chefs working in the SAME kitchen.

  • Share the same stove, utensils, ingredients
  • Can access each other’s workspace
  • If one chef makes a mess, everyone sees it
  • Cheap to add/remove chefs

Process vs Thread

AspectProcessThread
MemorySeparate memory spaceShared memory space
VariablesEach has its own copyAll share same variables
IsolationCompletely isolatedCan interfere with each other
Creation CostExpensive (fork/spawn)Cheap (just a new call stack)
CommunicationIPC (pipes, sockets)Direct (shared memory)
Crash impactIsolated (others survive)Can corrupt shared state
Python GILEach has own GILAll share one GIL