Subjects

All subjects Django Java Python React Spring Boot JavaScript PHP
Sign Up Free
Python 9 questions

Multithreading, Multiprocessing & Asyncio

Master concurrent execution in Python. Learn GIL constraints, threading vs processing, and async programming using asyncio.

More Python
Interview questions 1–9 of 9
1

What is the Global Interpreter Lock (GIL) and why does it matter?

The GIL is a mutex in CPython that allows only ONE thread to execute Python bytecode at a time, even on multi-...

Read answer →
2

What is the difference between threading and multiprocessing in Python?

AspectthreadingmultiprocessingMemoryShared memory spaceSeparate memory per processGIL impactLimited by GIL for...

Read answer →
3

How does asyncio work, and how is it different from threading?

asyncio provides concurrency within a SINGLE thread using cooperative multitasking - coroutines voluntarily yi...

Read answer →
4

How do you write and run coroutines with async/await in Python?

import asyncio # Defining a coroutine function async def greet(name): print(f'Hello, {name}') await a...

Read answer →
5

How do you prevent race conditions when using threads in Python?

A race condition occurs when multiple threads access and modify shared data simultaneously, producing unpredic...

Read answer →
6

When should you choose multiprocessing over asyncio, and vice versa?

ScenarioBest choiceReasonHeavy computation (image processing, math)multiprocessingTrue parallelism across CPU...

Read answer →
7

What is a deadlock and how can it happen with threads?

A deadlock occurs when two or more threads are each waiting for a resource held by the other, so none can proc...

Read answer →
8

What is the concurrent.futures module and how does it simplify thread/process pools?

concurrent.futures provides a high-level interface (ThreadPoolExecutor and ProcessPoolExecutor) for running ta...

Read answer →
9

How do you handle exceptions in threads and async tasks?

Exceptions raised inside a thread's target function don't automatically propagate to the main thread - they're...

Read answer →