FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
PythonLearning/74.MultiprocessingInPythonPart2.py at Pythontuts · aditya0035/PythonLearning · GitHub
aditya0035
/
PythonLearning
Public
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Issues
0
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
PythonLearning
/
74.MultiprocessingInPythonPart2.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
26 lines (22 loc) · 935 Bytes
Breadcrumbs
PythonLearning
/
74.MultiprocessingInPythonPart2.py
Copy path
File metadata and controls
26 lines (22 loc) · 935 Bytes
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
"""
like Threadpoolexecutor we have ProcessPoolExecutor in Concurrent.futures module
which will take care of all the process creation like thread pool executor does
"""
from
concurrent
.
futures
import
ProcessPoolExecutor
def
ask_user
():
user_input
=
input
(
"Enter Your Name"
)
greet
=
f'Hello
{
user_input
}
'
print
(
greet
)
def
Complex_Calculation
():
print
(
"Starting Calculation"
)
x
=
[
x
**
2
for
x
in
range
(
10000000
)]
print
(
"Ending Calculation"
)
def
Complex_Calculation_without_Resource
():
x
=
[
x
**
2
for
x
in
range
(
10000000
)]
if
__name__
==
'__main__'
:
#never forget that as in window when module load this file run
with
ProcessPoolExecutor
(
2
)
as
pool
:
# pool.submit(ask_user)
# pool.submit(Complex_Calculation)
pool
.
submit
(
Complex_Calculation_without_Resource
)
pool
.
submit
(
Complex_Calculation_without_Resource
)
#in this way we can get value from multiprocess
Back
|
FazBrowse Home
|
New Git URL