Home > other >  Queue catch exceptions jammed, how then collect the number
Queue catch exceptions jammed, how then collect the number

Time:11-17

In my queue q code as follows, take out an exception error after 0, then stuck, how to skip the number 0 took a


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
  • Related