sc_process.py 文件源码

python
阅读 18 收藏 0 点赞 0 评论 0

项目:pysc2 作者: deepmind 项目源码 文件源码
def _connect(self, port):
    """Connect to the websocket, retrying as needed. Returns the socket."""
    was_running = False
    for i in range(120):
      is_running = self.running
      was_running = was_running or is_running
      if (i >= 30 or was_running) and not is_running:
        logging.warning(
            "SC2 isn't running, so bailing early on the websocket connection.")
        break
      logging.info("Connection attempt %s (running: %s)", i, is_running)
      time.sleep(1)
      try:
        return websocket.create_connection("ws://127.0.0.1:%s/sc2api" % port,
                                           timeout=2 * 60)  # 2 minutes
      except socket.error:
        pass  # SC2 hasn't started listening yet.
      except websocket.WebSocketException as err:
        if "Handshake Status 404" in str(err):
          pass  # SC2 is listening, but hasn't set up the /sc2api endpoint yet.
        else:
          raise
    sys.exit("Failed to create the socket.")
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号