wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Python Threads

Total questions: 16

Worksheet time: 9mins

Name
Class
Date
1.

Which Python library runs a function as thread?

a)

None

b)

_threading

c)

threading

d)

thread

2.

How does run() method is invoked?

a)

By Thread.run()

b)

By Thread.start()

c)

By Thread.create()

d)

None

3.

How to terminate a blocking thread?

a)

thread.stop() & thread.wait()

b)

thread.stop()

c)

thread.terminate()

d)

None

4.

Which method is used to identify a thread?

a)

getThread()

b)

None

c)

getName()

d)

get_ident()

5.

What are the libraries in Python that support threads?

a)

_threading

b)

th

c)

None

d)

thread

6.

How does global value mutation used for thread-safety?

a)

via GIL (Global Interpreter Lock)

b)

via Locking

c)

via Mutex

d)

None

7.

What is the method to retrieve the list of all active threads?

a)

getList()

b)

getThreads()

c)

enumerate()

d)

threads()

8.

Which thread method is used to wait until it terminates?

a)

waitforthread()

b)

join()

c)

None

d)

wait()

9.

Multithreading is also called as ____________

a)

Concurrency

b)

Simultaneity

c)

Crosscurrent

d)

Recurrent

10.

A single sequential flow of control within a program is ________

a)

Process

b)

Task

c)

Thread

d)

Structure

11.

A method used to force one thread to wait for another thread to finish.

a)

join()

b)

connect()

c)

combine()

d)

concat()

12.

How many CPUs (or cores) will the Python threading library take advantage of simultaneously?

a)

Two

b)

One

c)

None

d)

All of the available CPUs

13.

What does the Thread.join() method do?

a)

Adds the thread to a pool

b)

Merges two threads into one

c)

Waits for the thread to finish

d)

Restricts access to a resource

14.

Race conditions are …

a)

Two threads incorrectly accessing a shared resource

b)

Testing which thread completes first

c)

Something you should add to your code

d)

The weather on race day

15.

Why is it a good idea to use a ThreadPoolExecutor as a context manager when you can?

a)

It looks better

b)

t passes exceptions back to the main program

c)

It manages the start up of all threads and waits for them all to complete

d)

It prevents the threads from having race conditions

16.

True or False? Once you start a threading.Timer, you cannot stop it until it expires.

a)

TRUE

b)

FALSE