menu

Python Concurrency and Parallelism


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

threading

multiprocessing

concurrent.futures

asyncio


2. What is the purpose of the lock object in Python threading?

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

To prevent deadlock in multithreaded code.

To provide a way to communicate between threads.

To provide a way to synchronize tasks between threads.


3. Which module is used to create and manage threads in Python?

threading

multiprocessing

concurrent.futures

asyncio


4. Which of the following is an example of a common use case for multithreading in Python?

Machine learning

GUI programming

Web scraping

Database programming


5. Which method is used to retrieve the result of a submitted task in Python?

result()

get()

retrieve()

fetch()


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

start()

run()

create()

initiate()


7. Which function is used to run an asyncio event loop?

asyncio.run()

asyncio.loop()

asyncio.start()

asyncio.stop()


8. What is the purpose of the concurrent.futures module in Python?

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

To provide a way to execute code concurrently using coroutines.

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

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


9. Which keyword is used to define a Python function as a coroutine?

async

await

coroutine

yield


10. Which of the following is a way to overcome the limitations of the GIL in Python?

Using multiprocessing instead of threading

Using asyncio instead of threading

Using coroutines instead of threads

Using locks to manage access to shared resources