code: def check_port(self, port):
          
          s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
          try:
              s.bind(("localhost", port))
          except socket.error:
              raise UnityWorkerInUseException(self.worker_id)
          finally:
              s.close()
docs: Attempts to bind to the requested communicator port, checking if it is already in use.