Skip to content

Commit d142ba4

Browse files
Good Programming Practices:Always release the lock in finally block.
1 parent 864fc21 commit d142ba4

1 file changed

Lines changed: 23 additions & 0 deletions

File tree

GoodProgrammingPractices1.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#Good Programming Practices:
2+
#1.Always release the lock in finally block
3+
4+
from threading import *
5+
import time
6+
l=Lock()
7+
def wish(name):
8+
l.acquire()
9+
try:
10+
for i in range(5):
11+
print("Good Evening:",flush=True,end='')
12+
time.sleep(2)
13+
print(name)
14+
finally:
15+
l.release()
16+
t1=Thread(target=wish,args=('Rishabh',))
17+
t2=Thread(target=wish,args=('Amol',))
18+
t3=Thread(target=wish,args=('Shreyash',))
19+
t1.start()
20+
t2.start()
21+
t3.start()
22+
23+

0 commit comments

Comments
 (0)