QuizzesThe GIL — Why Python Threads Don't Run in Parallel — Concept Check
intermediate
python

The GIL — Why Python Threads Don't Run in Parallel — Concept Check

Questions on The GIL — Why Python Threads Don't Run in Parallel. The Global Interpreter Lock lets only one thread execute Python bytecode at a time — so threads never speed up CPU-bound code, but still shine for I/O because the GIL is released while waiting.

7 minutes 7 questions Pass at 70%
Time Limit
7 minutes - timer starts when you begin
Change Answers Freely
Revisit and change any answer before submitting
Full Review After Submit
Correct answers and explanations shown for every question
Auto-submit on timeout
Quiz submits automatically when time runs out

Questions in this quiz

7 questions on The GIL — Why Python Threads Don't Run in Parallel — Concept Check. Work through them here, then start the quiz to answer them and see your score.

  1. 1.A Python application is running two threads to perform heavy calculations, but it shows no speedup on an 8-core machine. Why?

    • AThe threads are not correctly synchronized, causing a deadlock.
    • BThe GIL allows only one thread to execute Python bytecode at a time.
    • CThe operating system limits Python to a single core.
    • DPython threads are not compatible with multi-core processors.
  2. 2.You have a Python script that performs I/O-bound tasks using threads. What outcome can you expect?

    • AThe script will execute at the same speed as a single-threaded version.
    • BThe script will not execute because Python does not support threading for I/O.
    • CThe script will execute slower because threads compete for the GIL.
    • DThe script will execute faster because the GIL is released during I/O operations.
  3. 3.A developer is using threads in Python to parse large files. What is the likely result?

    • AThe program will crash due to excessive memory usage.
    • BThe threads will automatically distribute across all available cores.
    • CNo speedup, as parsing is CPU-bound and the GIL restricts parallel execution.
    • DSignificant speedup due to parallel processing of file data.
  4. 4.In Python, why might using threads for CPU-bound tasks not improve performance?

    • AThreads in Python are inherently slower than processes.
    • BPython threads cannot access multiple CPU cores.
    • CThe Python interpreter automatically disables threading for CPU-bound tasks.
    • DThe GIL prevents multiple threads from executing Python bytecode simultaneously.
  5. 5.A Python script uses threading to handle multiple API requests simultaneously. What is the expected behavior?

    • AThe script will handle requests efficiently by releasing the GIL during I/O.
    • BThe script will be inefficient because threads are blocked by the GIL.
    • CThe script will crash due to thread contention.
    • DThe script will handle requests one at a time.
  6. 6.Why might a Python program using NumPy see performance gains with threading?

    • ANumPy operations are inherently faster than Python loops.
    • BNumPy operations release the GIL, allowing parallel execution.
    • CNumPy operations bypass the GIL entirely, unlike Python bytecode.
    • DNumPy automatically optimizes thread usage for CPU-bound tasks.
  7. 7.What is a key reason for the existence of the GIL in CPython?

    • ATo simplify memory management by ensuring thread safety.
    • BTo allow Python to handle I/O-bound tasks more efficiently.
    • CTo prevent Python from being used in multi-core systems.
    • DTo enhance the performance of multi-threaded applications.