class_docstr: A rendezvous implementation that uses `etcd <https://etcd.io/>`__ as the backend store.
class_docstr_tok: ["A","rendezvous","implementation","that","uses","`","etcd","<","https",":","\/\/etcd.io\/",">","`","__","as","the","backend","store","."]
code: def setup_lease_renewal(self, full_path, ttl):
      # NOTE: For ephemeral key TTL renewal (~lease) to work correctly,
      # make sure you don't call any long-blocking methods that do not
      # release the Python's GIL! An example of this is calling a pybind11
      # extension function that is blocking / long-running, but is not
      # doing a scoped release of the GIL.
      def lease_worker(client, path, ttl, stop_event):
          while True:
              try:
                  client.refresh(path, ttl=ttl)
              except etcd.EtcdKeyNotFound:
                  break
              except ConnectionRefusedError:
                  # This error usually occurs during test when the server already got terminated but the
                  # python garbage collector have not yet invoked the __del__ method.
                  break
  
              if stop_event.wait(timeout=ttl / 2):
                  break
  
      lease_stop_event = threading.Event()
      lease_thread = threading.Thread(
          target=lease_worker,
          args=(self.client, full_path, ttl, lease_stop_event),
      )
  
      lease_thread.daemon = True
      lease_thread.start()
  
      return lease_stop_event
  
imports: import json
  import logging
  import sys
  import threading
  import time
  from typing import Optional
  import etcd
  from torch.distributed.elastic.rendezvous import RendezvousClosedError, RendezvousError, RendezvousHandler, RendezvousParameters, RendezvousTimeoutError
  from .utils import parse_rendezvous_endpoint
  from .etcd_store import EtcdStore, cas_delay
label_desc: Use image node_id 21 for calling the EtcdRendezvous obj's underlying member method code with example usage: obj.setup_lease_renewal(full_path, ttl) and returns: lease_stop_event