class_docstr: Class for clusters following a master-worker architecture.
  
  Usually you want to inherit from this class and do not want to use it directly. It is recommended to treat this
  class as an abstract class or an interface.
  
  Examples:
      Create a cluster with all `Runtimes` detected by the `RuntimeManager`.
  
      ```python
      from lazycluster import RuntimeManager
      cluster = MyMasterWorkerClusterImpl(RuntimeManager().create_group())
      cluster.start()
      ```
  
      Use different strategies for launching the master and the worker instance as the default ones by providing
      custom implementation of `MasterLauncher` and `WorkerLauncher`.
  
      ```python
      cluster = MyMasterWorkerClusterImpl(RuntimeManager().create_group(),
                                          MyMasterLauncherImpl(),
                                          MyWorkerLauncherImpl()
      cluster.start()
      ```
class_docstr_tok: ["Class","for","clusters","following","a","master-worker","architecture",".","Usually","you","want","to","inherit","from","this","class","and","do","not","want","to","use","it","directly",".","It","is","recommended","to","treat","this","class","as","an","abstract","class","or","an","interface",".","Examples",":","Create","a","cluster","with","all","`","Runtimes","`","detected","by","the","`","RuntimeManager","`",".","``","`","python","from","lazycluster","import","RuntimeManager","cluster","=","MyMasterWorkerClusterImpl","(","RuntimeManager","(",")",".create_group","(",")",")","cluster.start","(",")","``","`","Use","different","strategies","for","launching","the","master","and","the","worker","instance","as","the","default","ones","by","providing","custom","implementation","of","`","MasterLauncher","`","and","`","WorkerLauncher","`",".","``","`","python","cluster","=","MyMasterWorkerClusterImpl","(","RuntimeManager","(",")",".create_group","(",")",",","MyMasterLauncherImpl","(",")",",","MyWorkerLauncherImpl","(",")","cluster.start","(",")","``","`"]
docstr: Initialization method.
  
  Args:
      runtime_group: The `RuntimeGroup` contains all `Runtimes` which can be used for starting the cluster
                     entities.
      ports: The list of ports which will be used to instantiate a cluster. Defaults to
             `list(range(self.DEFAULT_PORT_RANGE_START, self.DEFAULT_PORT_RANGE_END)`.
      master_launcher: Optionally, an instance implementing the `MasterLauncher` interface can be given, which
                       implements the strategy for launching the master instances in the cluster. If None, then
                       the default of the concrete cluster implementation will be chosen.
      worker_launcher: Optionally, an instance implementing the `WorkerLauncher` interface can be given, which
                       implements the strategy for launching the worker instances. If None, then the default of
                       the concrete cluster implementation will be chosen.
docstr_tok: ["Initialization","method",".","Args",":","runtime_group",":","The","`","RuntimeGroup","`","contains","all","`","Runtimes","`","which","can","be","used","for","starting","the","cluster","entities",".","ports",":","The","list","of","ports","which","will","be","used","to","instantiate","a","cluster",".","Defaults","to","`","list","(","range","(","self.DEFAULT_PORT_RANGE_START",",","self.DEFAULT_PORT_RANGE_END",")","`",".","master_launcher",":","Optionally",",","an","instance","implementing","the","`","MasterLauncher","`","interface","can","be","given",",","which","implements","the","strategy","for","launching","the","master","instances","in","the","cluster",".","If","None",",","then","the","default","of","the","concrete","cluster","implementation","will","be","chosen",".","worker_launcher",":","Optionally",",","an","instance","implementing","the","`","WorkerLauncher","`","interface","can","be","given",",","which","implements","the","strategy","for","launching","the","worker","instances",".","If","None",",","then","the","default","of","the","concrete","cluster","implementation","will","be","chosen","."]
code: def __init__(
      self,
      runtime_group: RuntimeGroup,
      ports: Optional[List[int]] = None,
      master_launcher: Optional[MasterLauncher] = None,
      worker_launcher: Optional[WorkerLauncher] = None,
  ):
      """Initialization method.
  
      Args:
          runtime_group: The `RuntimeGroup` contains all `Runtimes` which can be used for starting the cluster
                         entities.
          ports: The list of ports which will be used to instantiate a cluster. Defaults to
                 `list(range(self.DEFAULT_PORT_RANGE_START, self.DEFAULT_PORT_RANGE_END)`.
          master_launcher: Optionally, an instance implementing the `MasterLauncher` interface can be given, which
                           implements the strategy for launching the master instances in the cluster. If None, then
                           the default of the concrete cluster implementation will be chosen.
          worker_launcher: Optionally, an instance implementing the `WorkerLauncher` interface can be given, which
                           implements the strategy for launching the worker instances. If None, then the default of
                           the concrete cluster implementation will be chosen.
      """
      # Create the Logger
      self.log = logging.getLogger(__name__)
  
      self._group = runtime_group
      self._ports = (
          ports
          if ports
          else list(
              range(
                  self.DEFAULT_PORT_RANGE_START,
                  self.DEFAULT_PORT_RANGE_END,
              )
          )
      )
      self._master_launcher = master_launcher
      self._worker_launcher = worker_launcher
  
      # Cleanup will be done atexit since usage of destructor may lead to exceptions
      atexit.register(self.cleanup)
  
      self.log.debug("MasterWorkerCluster initialized.")
  
imports: import atexit
  import logging
  from subprocess import Popen
  from typing import Dict, List, Optional, Union
  from lazycluster.exceptions import LazyclusterError
  from lazycluster.runtime_mgmt import RuntimeGroup
label_desc: Use image node_id 1 to create a new MasterWorkerCluster object from inherited base classes: RuntimeCluster with example: obj = MasterWorkerCluster(runtime_group, ports, master_launcher, worker_launcher)