Verified Jobs Live
Python Programming Advanced Level ~4 min read

Explain the difference between Python's GIL (Global Interpreter Lock) and multi-threading vs multi-processing.

Quick Revision Summary

The Python GIL ensures thread-safe reference counting in CPython. Use multiprocessing for CPU-bound operations and multithreading for I/O operations.

Interactive Practice Mode
Formulate your thoughts or take notes before revealing the model solution.
Model Answer & Deep-Dive Explanation

The Global Interpreter Lock (GIL) is a mutex in CPython that prevents multiple native threads from executing Python bytecodes simultaneously. Even on a multi-core machine, only one thread can execute Python code at any single instant.

Because of the GIL:

  • Multi-threading (threading module): Best suited for I/O-bound tasks (e.g. web scraping, file I/O, database querying). While one thread waits for network or disk response, the GIL is released, allowing other threads to run.
  • Multi-processing (multiprocessing module): Recommended for CPU-bound computations (e.g. mathematical transformations, image processing). Each process spawns its own Python interpreter and memory space, effectively bypassing the GIL and utilizing 100% of multi-core processors.

Interviewer Evaluation Points & Scoring Rubric

  • 1 1. Correctly states CPython mutex limitation. 2. Explains CPU-bound vs I/O-bound distinction. 3. Identifies the multiprocessing module for true parallel execution.