class_docstr: A simple counter object that can periodically sync with a parent.
class_docstr_tok: ["A","simple","counter","object","that","can","periodically","sync","with","a","parent","."]
docstr: Initialize the counter.
  
  Args:
    parent: a Counter object to cache locally (or None for no caching).
    prefix: string prefix to use for all local counts.
    time_delta: time difference in seconds between syncing with the parent
      counter.
    return_only_prefixed: if True, and if `prefix` isn't empty, return counts
      restricted to the given `prefix` on each call to `increment` and
      `get_counts`. The `prefix` is stripped from returned count names.
docstr_tok: ["Initialize","the","counter",".","Args",":","parent",":","a","Counter","object","to","cache","locally","(","or","None","for","no","caching",")",".","prefix",":","string","prefix","to","use","for","all","local","counts",".","time_delta",":","time","difference","in","seconds","between","syncing","with","the","parent","counter",".","return_only_prefixed",":","if","True",",","and","if","`","prefix","`","is","n't","empty",",","return","counts","restricted","to","the","given","`","prefix","`","on","each","call","to","`","increment","`","and","`","get_counts","`",".","The","`","prefix","`","is","stripped","from","returned","count","names","."]
code: def __init__(
      self,
      parent: Optional["Counter"] = None,
      prefix: str = "",
      time_delta: float = 1.0,
      return_only_prefixed: bool = False,
  ):
      """Initialize the counter.
  
      Args:
        parent: a Counter object to cache locally (or None for no caching).
        prefix: string prefix to use for all local counts.
        time_delta: time difference in seconds between syncing with the parent
          counter.
        return_only_prefixed: if True, and if `prefix` isn't empty, return counts
          restricted to the given `prefix` on each call to `increment` and
          `get_counts`. The `prefix` is stripped from returned count names.
      """
  
      self._parent = parent
      self._prefix = prefix
      self._time_delta = time_delta
  
      # Hold local counts and we'll lock around that.
      # These are counts to be synced to the parent and the cache.
      self._counts = {}
      self._lock = threading.Lock()
  
      # We'll sync periodically (when the last sync was more than self._time_delta
      # seconds ago.)
      self._cache = {}
      self._last_sync_time = 0.0
  
      self._return_only_prefixed = return_only_prefixed
  
file_path: acme/acme/utils/counting.py
imports: import threading
  import time
  from typing import Dict, Mapping, Optional, Union
  from acme import core
label_desc: Use image node_id 1 to create a new Counter object from inherited base classes: core with example: obj = Counter(parent, prefix, time_delta, return_only_prefixed)