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","."]
code: def _bind_socket(self):
      try:
          win_in_use = errno.WSAEADDRINUSE  # type:ignore[attr-defined]
      except AttributeError:
          win_in_use = None
  
      # Try up to 100 times to bind a port when in conflict to avoid
      # infinite attempts in bad setups
      max_attempts = 1 if self.original_port else 100
      for attempt in range(max_attempts):
          try:
              self._try_bind_socket()
          except zmq.ZMQError as ze:
              if attempt == max_attempts - 1:
                  raise
              # Raise if we have any error not related to socket binding
              if (
                  ze.errno != errno.EADDRINUSE
                  and ze.errno != win_in_use
              ):
                  raise
              # Raise if we have any error not related to socket binding
              if self.original_port == 0:
                  self.pick_port()
              else:
                  raise
          else:
              return
  
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 4 for calling the Heartbeat obj's underlying member method code with example usage: obj._bind_socket() without return types