title: Why is my program keep trying to take all of available CPU
body: <p><a href="https://i.stack.imgur.com/CoFRY.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/CoFRY.png" alt="enter image description here" /></a></p>
  <p>As you can see from above the process keep trying to take as many cpu resource as possible. On the picture above I am only using  camera sources to test. As you could see below that I repeat each process for each camera available. Initially I thought the reason is that my cpu have not enough power but adding several more camera. None of the camera is laggy in fact and all is on about the same fps as only 1 camera which make me question what is the actual cause because apparently it is not cause by lack of resources from my CPU. Below is my main program.</p>
  <pre><code>import cProfile
  from multiprocessing import Process
  import sys
  import threading
  import videoPlayerThreading as vpt
  from objDect import objDect as od
  
  def main(videoSource):
      obd = od( videoSources = videoSource, GPU=True )
      
      getFrame = vpt.getFrames(videoSource).start()
      showFrame = vpt.showFrames(getFrame.frame).start()
  
      getFrame.videoInit(videoSource)
  
      print(&quot;Showing Frame...&quot;)
      while True:
          print(&quot;thread count : &quot;,threading.active_count())
          frame = getFrame.frame
          #frame = obd.predictYolo(frame)
          
  
          showFrame.frame = frame
   
          if getFrame.doVideo == False or showFrame.doVideo == False:
              getFrame.stop()
              showFrame.stop()
              sys.exit()
  
  def working():
      cams=[0,1,2]
      for cam in cams:
          Process(target=main,args=(cam,)).start()
  
  if __name__==&quot;__main__&quot;:
      working()
  </code></pre>
  <p>and here is my getFrame and showFrame class:</p>
  <pre><code>class getFrames():
      def __init__(self, 
                   videoSource:Union[int,str]=0):
          self.stream = self.videoInit(videoSource)
          self.hasFrame, self.frame = self.stream.read()
          self.doVideo = True
  
      def videoInit(self,
                    videoSource:Union[int,str]):
          try:
              cap = cv2.VideoCapture(videoSource)
          except Exception as e:
              raise Exception(f&quot;Video source error: {e}&quot;)
  
          return cap
  
      def start(self):
          Thread(target=self.getFrames, args=()).start()
          return self
  
      def getFrames(self):
          while self.doVideo:
              if not self.hasFrame:
                  self.stop()
              else:
                  (self.hasFrame, self.frame) = self.stream.read()
  
      def stop(self):
          self.doVideo = False
          self.stream.release()
  
  class showFrames():
      def __init__(self, 
                   frame:cv2=None):
          self.frame = frame
          self.doVideo = True
  
      def start(self):
          Thread(target=self.showFrame, args=()).start()
          return self
  
      def showFrame(self):
          while self.doVideo:
              cv2.imshow(&quot;Video&quot;, self.frame)
              if cv2.waitKey(1) == ord(&quot;q&quot;):
                  self.doVideo = False
  
      def stop(self):
          self.doVideo = False
  </code></pre>
  <p>and lastly here is my objdect.predict :</p>
  <pre><code> @jit(nopython=True, parallel=True) 
      def predictYolo(self,
                      frame:cv2) -&gt; cv2:
          net = self.net
  
          height, width, channels = frame.shape
          
          blob = cv2.dnn.blobFromImage(frame, 1 / 255.0, (416, 416),swapRB=True, crop=False)       
          net.setInput(blob)
          outs = net.forward(self.output_layers)
          
          class_ids = []
          confidences = []
          boxes = []
          for out in outs:
              for detection in out:
                  scores = detection[5:]
                  class_id = np.argmax(scores)
                  confidence = scores[class_id]
                  if confidence &gt; 0.8:
                      # Object detected
                      center_x = int(detection[0] * width)
                      center_y = int(detection[1] * height)
                      w = int(detection[2] * width)
                      h = int(detection[3] * height)
  
                      # Rectangle coordinates
                      x = int(center_x - w / 2)
                      y = int(center_y - h / 2)
  
                      boxes.append([x, y, w, h])
                      confidences.append(float(confidence))
                      class_ids.append(class_id)
  
          indexes = cv2.dnn.NMSBoxes(boxes, confidences, 0.7, 0.4)
          font = cv2.FONT_HERSHEY_PLAIN
          classes=self.classes
          colors = np.random.uniform(130, 255, size=(len(classes), 3))
          for i in range(len(boxes)):
              if i in indexes:
                  x, y, w, h = boxes[i]
                  label = str(classes[class_ids[i]])
                  if label==&quot;With Helmet&quot;:
                      label=&quot;Helmet&quot;
                      color=(0,255,0)
                  elif label==&quot;Without Helmet&quot;:
                      label=&quot;Violation&quot;
                      color=(0,0,255)
                
                  self.createBB(x,y,w,h,frame=frame,label=label,color=color)
          self.frame=frame
          #print(&quot;sending finish processed frame ...&quot;)
          return frame
  
  </code></pre>
  <p>Is there any Error in the program that cause the code to always try to take maximum cpu resource? Thanks.</p>