code: def close_dut(self, use_prepare=True):
          
          if not self.stopped:
              self.logger.debug("Close '%s' connection" % self.dut_name, extra={'type': '<->'})
              if use_prepare:
                  try:
                      self.prepare_connection_close()
                  except TestStepFail:
                      # We can ignore this for dead Duts, just continue with cleanup
                      pass
              self.stopped = True
              Dut._dutlist.remove(self)
              # Remove myself from signalled dut list, if I'm still there
              if Dut._signalled_duts and Dut._signalled_duts.count(self):
                  try:
                      Dut._signalled_duts.remove(self)
                  except ValueError:
                      pass
  
              try:
                  if not Dut._dutlist:
                      Dut._run = False
                      Dut._sem.release()
                      Dut._th.join()
                      del Dut._th
                      Dut._th = None
              except AttributeError:
                  pass
docs: Close connection to dut.
  
          :param use_prepare: Boolean, default is True. Call prepare_connection_close before
          closing connection.
          :return: Nothing