Class saver (threading. Thread) :
Def __init__ (self, q) :
The self, super (saver) __init__ ()
Self. Q=q
Def run (self) - & gt; None:
Global n
While True:
Try:
Y=self. Q.g et ()
Glock. Acquire ()
N=n + 1
Print (y)
Print (1/y)
Print (% n % d times calculation)
Glock. Release ()
Except the Exception as e:
Print (e)
Def the main () :
Ls=[random randint (0, 5) for I in range (20)]
Q=queue. The queue ()
For l in ls:
Q.p ut (l)
For x in range (5) :
Th=saver (q)
Th. The start ()
If __name__=="__main__ ':
The main ()
CodePudding user response:
The glock. Release () writes the finally:CodePudding user response:
Glock is used to lock n, not delete the