menu

Python Concurrency and Parallelism


1. What is the purpose of the asyncio module in Python?

To provide a way to execute code concurrently using threads and processes.

To provide a way to execute code concurrently using coroutines.

To provide a way to manage and control concurrency in Python code.

To provide a way to create and manage threads and processes.


2. Which of the following statements is true regarding Global Interpreter Lock (GIL)?

It allows multiple threads to execute simultaneously.

It allows multiple processes to execute simultaneously.

It allows only one thread to execute at a time.

It allows only one process to execute at a time.


3. Which of the following is an example of a parallel processing library in Python?

NumPy

Pandas

TensorFlow

Flask


4. What is the difference between concurrency and parallelism?

Concurrency refers to the ability to execute multiple tasks simultaneously, while parallelism refers to the ability to execute multiple tasks on multiple processors simultaneously.

Concurrency refers to the ability to execute multiple tasks on multiple processors simultaneously, while parallelism refers to the ability to execute multiple tasks simultaneously.

Concurrency refers to the ability to execute multiple tasks on a single processor simultaneously, while parallelism refers to the ability to execute multiple tasks on multiple processors simultaneously.

Concurrency and parallelism are the same thing.


5. Which module is used to create and manage processes in Python?

threading

multiprocessing

concurrent.futures

asyncio


6. What is the purpose of the Queue class in Python threading?

To provide a way to communicate between threads.

To prevent race conditions in multithreaded code.

To ensure only one thread can access a shared resource at a time.

To provide a way to limit the number of threads that can access a resource at a time.


7. Which module is used to manage a pool of worker processes in Python?

threading

multiprocessing

concurrent.futures

asyncio


8. Which of the following is a method of creating a new thread in Python?

Using the multiprocessing module

Using the threading module

Using the concurrent.futures module

Using the asyncio module


9. Which method is used to create a thread in Python?

start()

run()

create()

initiate()


10. Which module provides a high-level interface for asynchronously executing functions and methods?

threading

multiprocessing

concurrent.futures

asyncio