parameters: (self)
docstring: Initialize handle and devices if not already done so.
docstring_summary: Initialize handle and devices if not already done so.
docstring_tokens: Initialize handle and devices if not already done so .
function: def ensure_initialized(self):
      """Initialize handle and devices if not already done so."""
      if self._initialized:
        return
      with self._initialize_lock:
        if self._initialized:
          return
        assert self._context_devices is None
        opts = pywrap_tensorflow.TFE_NewContextOptions()
        try:
          config_str = self.config.SerializeToString()
          pywrap_tensorflow.TFE_ContextOptionsSetConfig(opts, config_str)
          if self._device_policy is not None:
            pywrap_tensorflow.TFE_ContextOptionsSetDevicePlacementPolicy(
                opts, self._device_policy)
          if self._mirroring_policy is not None:
            pywrap_tensorflow.TFE_ContextOptionsSetMirroringPolicy(
                opts, self._mirroring_policy)
          if self._default_is_async == ASYNC:
            pywrap_tensorflow.TFE_ContextOptionsSetAsync(opts, True)
          context_handle = pywrap_tensorflow.TFE_NewContext(opts)
        finally:
          pywrap_tensorflow.TFE_DeleteContextOptions(opts)
        assert not (self._server_def and self._collective_ops_server_def), (
            "Cannot enable remote execution as well as collective ops at the "
            "moment. If this is important to you, please file an issue.")
        if self._server_def is not None:
          server_def_str = self._server_def.SerializeToString()
          pywrap_tensorflow.TFE_ContextSetServerDef(context_handle, 600,
                                                    server_def_str)
        elif self._collective_ops_server_def is not None:
          server_def_str = self._collective_ops_server_def.SerializeToString()
          pywrap_tensorflow.TFE_EnableCollectiveOps(context_handle,
                                                    server_def_str)
  
        self._context_handle = context_handle
        self._initialize_logical_devices()
        self._initialized = True
function_tokens: def ensure_initialized ( self ) : if self . _initialized : return with self . _initialize_lock : if self . _initialized : return assert self . _context_devices is None opts = pywrap_tensorflow . TFE_NewContextOptions ( ) try : config_str = self . config . SerializeToString ( ) pywrap_tensorflow . TFE_ContextOptionsSetConfig ( opts , config_str ) if self . _device_policy is not None : pywrap_tensorflow . TFE_ContextOptionsSetDevicePlacementPolicy ( opts , self . _device_policy ) if self . _mirroring_policy is not None : pywrap_tensorflow . TFE_ContextOptionsSetMirroringPolicy ( opts , self . _mirroring_policy ) if self . _default_is_async == ASYNC : pywrap_tensorflow . TFE_ContextOptionsSetAsync ( opts , True ) context_handle = pywrap_tensorflow . TFE_NewContext ( opts ) finally : pywrap_tensorflow . TFE_DeleteContextOptions ( opts ) assert not ( self . _server_def and self . _collective_ops_server_def ) , ( "Cannot enable remote execution as well as collective ops at the " "moment. If this is important to you, please file an issue." ) if self . _server_def is not None : server_def_str = self . _server_def . SerializeToString ( ) pywrap_tensorflow . TFE_ContextSetServerDef ( context_handle , 600 , server_def_str ) elif self . _collective_ops_server_def is not None : server_def_str = self . _collective_ops_server_def . SerializeToString ( ) pywrap_tensorflow . TFE_EnableCollectiveOps ( context_handle , server_def_str ) self . _context_handle = context_handle self . _initialize_logical_devices ( ) self . _initialized = True