Threading Flashcards

1
Q

Thread

A

A flow of execution. Like a separate order of instructions. However each thread takes a turn running to achieve concurrency.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

GIL

A

Global interpreter lock- allows only one thread to hold the control of the Python interpreter at any one time

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Cpu bound

A

Program/task spends most of its time waiting for internal events (CPU intensive) uses multiprocessing

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Io bound

A

Program/task spends most of its time waiting for external events(user input, web scraping)
Uses multithreading

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Daemon thread

A

A thread that runs in the background, not important for program to run, your program won’t wait got daemon threads to complete before exiting, non- daemon threads cannot normally be killed, stay alive till complete

E.g background tasks, waiting for input , garbage collection, long processes

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Syntax for normal thread

A

Variable = threading.thread(target=-function-)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Daemon thread syntax

A

Variable = threading.thread(target=-function-, daemon=True)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

To check if a thread is a daemon thread

A

Print(x.isdaemon)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Multiprocessing explained:

A

Running tasks in parallel on different cpu cores, bypassed GIL used for threading

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What are multithreading and multiprocessing good for?

A

Multiprocessing = better for cpu bound tasks (heavy cpu usage)

Multithreading = better for io bound tasks (waiting around)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What does “ if __name__ == ‘__main__’:
main()

Def main():
Pass

A

It means that when child processes are made from the main module they will copy them but won’t execute

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What are the parameters for a thread?

A

Variable = threading.thread(target=~~,args=(~~))

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Process syntax

A

Variable = process(target=~~,args=(~~))
Variable.start

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What function gives synchronicity?

A

Join() function

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What part of the cpu completes processes?

A

The cpu cores

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What is the amount of processes you can complete at one time dependent on?

A

How many cores you have