class_docstr: Scheduler extension - server side of MemorySampler
class_docstr_tok: ["Scheduler","extension","-","server","side","of","MemorySampler"]
docstr: Start periodically sampling memory
docstr_tok: ["Start","periodically","sampling","memory"]
code: def start(self, client: str, measure: str, interval: float) -> str:
      """Start periodically sampling memory"""
      assert not measure.startswith("_")
      assert isinstance(getattr(self.scheduler.memory, measure), int)
  
      key = str(uuid.uuid4())
      self.samples[key] = []
  
      def sample():
          if client in self.scheduler.clients:
              ts = datetime.now().timestamp()
              nbytes = getattr(self.scheduler.memory, measure)
              self.samples[key].append((ts, nbytes))
          else:
              self.stop(key)
  
      pc = PeriodicCallback(sample, interval * 1000)
      self.scheduler.periodic_callbacks["MemorySampler-" + key] = pc
      pc.start()
  
      # Immediately collect the first sample; this also ensures there's always at
      # least one sample
      sample()
  
      return key
  
file_path: distributed/distributed/diagnostics/memory_sampler.py
imports: from __future__ import annotations
  import uuid
  from collections.abc import AsyncIterator, Iterator
  from contextlib import asynccontextmanager, contextmanager
  from datetime import datetime
  from typing import TYPE_CHECKING, Any
  from distributed.compatibility import PeriodicCallback
label_desc: Use image node_id 2 for calling the MemorySamplerExtension obj's underlying member method code with example usage: obj.start(client, measure, interval) and returns: key