class_docstr: parallel.Execution is a tool for writing easy threading-based parallel tests.
  
  Execution.run is the main helper function, but there are a few magic getters that return
  correct thread-specific values when called from within an Execution.run-wrapped function.
  
  Example usage:
  
      SIZE = 10
      with parallel.Execution(SIZE) as pex:
          @pex.run
          def all_ranks():
              return pex.rank
  
          assert all_ranks == list(range(SIZE))
class_docstr_tok: ["parallel.Execution","is","a","tool","for","writing","easy","threading-based","parallel","tests",".","Execution.run","is","the","main","helper","function",",","but","there","are","a","few","magic","getters","that","return","correct","thread-specific","values","when","called","from","within","an","Execution.run-wrapped","function",".","Example","usage",":","SIZE","=","10","with","parallel.Execution","(","SIZE",")","as","pex",":","@","pex.run","def","all_ranks","(",")",":","return","pex.rank","assert","all_ranks","==","list","(","range","(","SIZE",")",")"]
docstr: Only callable within an @Execution.run-wrapped function.
  
  Use the thread identifier to figure out what the rank is for the caller, and return the
  rank of that caller.
  
  This is syntactic sugar to avoid having to write a large number of functions that take
  parameters of (rank, cross_rank, local_rank).
docstr_tok: ["Only","callable","within","an","@","Execution.run-wrapped","function",".","Use","the","thread","identifier","to","figure","out","what","the","rank","is","for","the","caller",",","and","return","the","rank","of","that","caller",".","This","is","syntactic","sugar","to","avoid","having","to","write","a","large","number","of","functions","that","take","parameters","of","(","rank",",","cross_rank",",","local_rank",")","."]
code: def rank(self) -> int:
      """
      Only callable within an @Execution.run-wrapped function.
  
      Use the thread identifier to figure out what the rank is for the caller, and return the
      rank of that caller.
  
      This is syntactic sugar to avoid having to write a large number of functions that take
      parameters of (rank, cross_rank, local_rank).
      """
      thread_id = threading.get_ident()
      assert (
          thread_id in self._info
      ), "must be called from within an @Execute-decorated function"
      return self._info[thread_id][0]
  
file_path: determined/harness/tests/parallel.py
imports: import contextlib
  import itertools
  import sys
  import threading
  import traceback
  from typing import Any, Callable, Dict, Iterator, List, Tuple, TypeVar
  import pytest
  from determined import core
label_desc: Use image node_id 5 for calling the Execution obj's underlying member method code with example usage: obj.rank() and returns: self