etha.kvstore.tcp
================

.. py:module:: etha.kvstore.tcp

.. autoapi-nested-parse::

   TorchTCPStore implementation wrapping torch.distributed.TCPStore.



Attributes
----------

.. autoapisummary::

   etha.kvstore.tcp.POLL_INTERVAL
   etha.kvstore.tcp.logger


Classes
-------

.. autoapisummary::

   etha.kvstore.tcp.TorchTCPStore


Module Contents
---------------

.. py:class:: TorchTCPStore(host: str, port: int, world_size: int, is_master: bool, timeout: float = 3600.0, wait_for_workers: bool = True, namespace: str = 'default', component: str = 'tensorbus')

   Bases: :py:obj:`etha.kvstore.base.KVStore`


   KVStore implementation backed by torch.distributed.TCPStore.

   This is a fallback implementation when etcd is not available.
   Uses polling for wait_for_keys (less efficient than etcd's watch).

   Initialize TorchTCPStore.

   :param host: TCPStore server host
   :param port: TCPStore server port
   :param world_size: Total number of processes
   :param is_master: Whether this process is the master (server)
   :param timeout: Connection timeout in seconds
   :param wait_for_workers: Whether master should wait for all workers
   :param namespace: Namespace for key isolation
   :param component: Default component name


   .. py:method:: close(cleanup: bool = True) -> None

      Close the store.

      Note: TCPStore doesn't have an explicit close method.

      :param cleanup: Ignored for TCPStore (no persistent storage)



   .. py:method:: delete(key: str, *, component: str | None = None) -> bool

      Delete a key.

      Note: TCPStore doesn't support delete, so we set value to empty string.



   .. py:method:: exists(key: str, *, component: str | None = None) -> bool

      Check if a key exists.



   .. py:method:: get(key: str, *, component: str | None = None) -> bytes | None

      Get value for a key.



   .. py:method:: get_bytes(key: str, *, component: str | None = None) -> bytes | None

      Retrieve binary data with base64 decoding.



   .. py:method:: set(key: str, value: str, *, component: str | None = None) -> None

      Set a key-value pair.



   .. py:method:: set_bytes(key: str, data: bytes, *, component: str | None = None) -> None

      Store binary data with base64 encoding (TCPStore only accepts strings).



   .. py:method:: wait_for_key(key: str, timeout: float = 3600.0, *, component: str | None = None) -> bytes

      Wait for a key to exist and return its value.

      Uses polling since TCPStore doesn't support watch.



   .. py:method:: wait_for_keys(key_pattern: str, expected_count: int, value: str = '1', timeout: float = 3600.0, candidate_keys: list[str] | None = None, *, component: str | None = None) -> list[str]

      Wait for keys matching pattern using polling.

      Since TCPStore doesn't support prefix listing or watch,
      we need candidate_keys to know which keys to check.

      :param key_pattern: Pattern with '*' wildcard
      :param expected_count: Number of matching keys to wait for
      :param value: Expected value for matching keys
      :param timeout: Maximum time to wait in seconds
      :param candidate_keys: List of keys to check (required for TCPStore)
      :param component: Override default component for this call

      :returns: List of matched keys (without namespace prefix)

      :raises TimeoutError: If timeout reached
      :raises ValueError: If candidate_keys not provided



   .. py:method:: wait_for_value(key: str, expected: str, timeout: float = 3600.0, *, component: str | None = None) -> bytes

      Wait for a key to have a specific value using polling.



   .. py:attribute:: host


   .. py:attribute:: is_master


   .. py:attribute:: port


   .. py:attribute:: world_size


.. py:data:: POLL_INTERVAL
   :value: 0.001


.. py:data:: logger

