class_docstr: A simple ping-pong style heartbeat that runs in a thread.
class_docstr_tok: ["A","simple","ping-pong","style","heartbeat","that","runs","in","a","thread","."]
docstr: Pick a port for the heartbeat.
docstr_tok: ["Pick","a","port","for","the","heartbeat","."]
code: def pick_port(self):
      """Pick a port for the heartbeat."""
      if self.transport == "tcp":
          s = socket.socket()
          # '*' means all interfaces to 0MQ, which is '' to socket.socket
          s.bind(("" if self.ip == "*" else self.ip, 0))
          self.port = s.getsockname()[1]
          s.close()
      elif self.transport == "ipc":
          self.port = 1
          while Path(f"{self.ip}-{self.port}").exists():
              self.port = self.port + 1
      else:
          raise ValueError(
              "Unrecognized zmq transport: %s" % self.transport
          )
      return self.port
  
file_path: catboost/contrib/python/ipykernel/py3/ipykernel/heartbeat.py
imports: import errno
  import socket
  from pathlib import Path
  from threading import Thread
  import zmq
  from jupyter_client.localinterfaces import localhost
label_desc: Use image node_id 2 for calling the Heartbeat obj's underlying member method code with example usage: obj.pick_port() and returns: self