class_docstr: ``PreemptContext`` gives access to preemption signals that originate from a user action, such as
  pausing an experiment using the WebUI or the CLI, from in the Determined scheduler.
class_docstr_tok: ["``","PreemptContext","``","gives","access","to","preemption","signals","that","originate","from","a","user","action",",","such","as","pausing","an","experiment","using","the","WebUI","or","the","CLI",",","from","in","the","Determined","scheduler","."]
code: def __init__(
      self,
      session: api.Session,
      allocation_id: str,
      dist: core.DistributedContext,
      preempt_mode: PreemptMode = PreemptMode.WorkersAskChief,
  ) -> None:
      self._session = session
      self._allocation_id = allocation_id
      self._dist = dist
      self._preempt_mode = PreemptMode(preempt_mode)
      self._watcher = None
      self._started = False
      if (
          self._dist.get_rank() == 0
          or self._preempt_mode == PreemptMode.WorkersAskMaster
      ):
          self._watcher = _PreemptionWatcher(session, allocation_id)
      self._ack_sent = False
  
imports: import enum
  import logging
  import threading
  import time
  from typing import Any, Optional
  import requests
  from determined import core
  from determined.common import api
label_desc: Use image node_id 1 to create a new PreemptContext object  with example: obj = PreemptContext(session, allocation_id, dist, preempt_mode)