-
Notifications
You must be signed in to change notification settings - Fork 16
/
0.MultiprocessingAndMultithreadingDifference.py
58 lines (47 loc) · 2.36 KB
/
0.MultiprocessingAndMultithreadingDifference.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
##------------------------------------------------------------------------------------------------------
#Created By:Ravishankar Chavare
#version:python 3.7
#Date:10/04/2019
#File_des:Difference Between Multiprocessing and Multithreading
##------------------------------------------------------------------------------------------------------
'''
Multiprocessing and Multithreading both adds performance to the system.
-Multiprocessing is adding more number of or CPUs/processors to the system which
increases the computing speed of the system.
-Multithreading is allowing a process to create more threads which increase the
responsiveness of the system
In Python, because of GIL (Global Interpreter Lock) a single python process cannot run threads
in parallel (utilize multiple cores).
It can however run them concurrently (context switch during I/O bound operations)
'''
#--------------------------------------------------------------------------------------------------#
# MultiProcessing
#--------------------------------------------------------------------------------------------------#
'''
Pros:-
-Multiprocessing achieves true parallelism and is used for CPU-bound tasks
-Multiprocessing adds CPUs to increase computing power.
-Multiple processes are executed concurrently.
-Separate memory space.
-Avoids GIL limitations for cPython(Global Interpreter Lock for accessing Same Memory Location)
-Child processes are interruptible/killable
-multiprocessing module is used in Python
Cons:-
-Larger memory footprint
Memory footprint refers to the amount of main memory that a program uses or references while running.
'''
#--------------------------------------------------------------------------------------------------#
# MultiThreading
#--------------------------------------------------------------------------------------------------#
'''
Pros:-
-Multithreading is concurrent and is used for IO-bound tasks
-Multithreading creates multiple threads of a single process to increase computing power.
-Multiple threads of a single process are executed concurrently.
-Shared memory - makes access to state from another context easier
-Allows you to easily make responsive UIs
-Lightweight - low memory footprint
Cons:-
-Complex debugging and testing processes
-Increased potential for deadlock occurrence(When Memory Leak)
'''