class_docstr: .. note:: tested on etcd server v3.4.3.
  
  Starts and stops a local standalone etcd server on a random free
  port. Useful for single node, multi-worker launches or testing,
  where a sidecar etcd server is more convenient than having to
  separately setup an etcd server.
  
  This class registers a termination handler to shutdown the etcd
  subprocess on exit. This termination handler is NOT a substitute for
  calling the ``stop()`` method.
  
  The following fallback mechanism is used to find the etcd binary:
  
  1. Uses env var TORCHELASTIC_ETCD_BINARY_PATH
  2. Uses ``<this file root>/bin/etcd`` if one exists
  3. Uses ``etcd`` from ``PATH``
  
  Usage
  ::
  
   server = EtcdServer("/usr/bin/etcd", 2379, "/tmp/default.etcd")
   server.start()
   client = server.get_client()
   # use client
   server.stop()
  
  Args:
      etcd_binary_path: path of etcd server binary (see above for fallback path)
code: def __init__(self, data_dir: Optional[str] = None):
      self._port = -1
      self._host = "localhost"
  
      root = os.path.dirname(__file__)
      default_etcd_bin = os.path.join(root, "bin/etcd")
      self._etcd_binary_path = os.environ.get(
          "TORCHELASTIC_ETCD_BINARY_PATH", default_etcd_bin
      )
      if not os.path.isfile(self._etcd_binary_path):
          self._etcd_binary_path = "etcd"
  
      self._base_data_dir = (
          data_dir
          if data_dir
          else tempfile.mkdtemp(prefix="torchelastic_etcd_data")
      )
      self._etcd_cmd = None
      self._etcd_proc: Optional[subprocess.Popen] = None
  
imports: import atexit
  import logging
  import os
  import shlex
  import shutil
  import socket
  import subprocess
  import tempfile
  import time
  from typing import Optional, TextIO, Union
label_desc: Use image node_id 1 to create a new EtcdServer object  with example: obj = EtcdServer(data_dir)