FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
PythonLearning/77.SharedResourceInPython.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
/
77.SharedResourceInPython.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
33 lines (32 loc) · 957 Bytes
Breadcrumbs
PythonLearning
/
77.SharedResourceInPython.py
Copy path
File metadata and controls
33 lines (32 loc) · 957 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
27
28
29
30
31
32
33
"""
Atomic Operation:That can't be interrupted at middle
e.g. print before we remove the thread from queue
"""
from
threading
import
Thread
import
time
import
random
counter
=
0
def
Incresment_Conuter
():
global
counter
time
.
sleep
(
random
.
randint
(
1
,
10
))
counter
+=
1
time
.
sleep
(
random
.
randint
(
1
,
10
))
print
(
f'Now Counter Value is
{
counter
}
'
)
print
(
"------------------"
)
threadList
=
[]
for
x
in
range
(
10
):
t
=
Thread
(
target
=
Incresment_Conuter
)
time
.
sleep
(
random
.
randint
(
1
,
10
))
t
.
start
()
threadList
.
append
(
t
)
print
(
"Thread Started"
)
"""
Here each time a new thread will be started
"""
for
thread
in
threadList
:
thread
.
join
()
"""
Here the thing are happening so fast that it looks like the method is calling sequencely
So see the actual behaviour we need to add some delay using time.sleep() this is called fuzzing in multithreading
as it help us to see the problem
"""
Back
|
FazBrowse Home
|
New Git URL