Python Multithreading--Part3 when multiple thread calling one method of code simulteniously then Lock(), acquire() and release() method will do synchronisation....
# -*- coding: utf-8 -*- """ Created on Fri Sep 30 14:01:03 2022 @author: Mahesh.Keshniya Python Multithreading--Part3 when multiple thread calling one method of code simulteniously then Lock(), acquire() and release() method will do synchronisation.... """ from threading import * class Myclass: def __init__(self,totalTicket): self.totalTicket=totalTicket self.lock=Lock() # locking def bookTicket(self,NeedToBookTicket): self.lock.acquire() # locking start print(f"Total Ticket Required by Thread/Customer Name{current_thread().name} is :{NeedToBookTicket}") if(NeedToBookTicket<=self.totalTicket): print(f"Ticket Boocked for Thread/Customer: {current_thread().name}") self.totalTicket -=1 else: ...