def set_default_executor(executor_factory_instance=None):
    """Places an `executor`-backed execution context at the top of the stack.

  Args:
    executor_factory_instance: An instance of
      `executor_factory.ExecutorFactory`, or `None` for the default executor.
  """
    if executor_factory_instance is None:
        context = None
    elif isinstance(executor_factory_instance,
                    executor_factory.ExecutorFactory):
        context = execution_context.ExecutionContext(executor_factory_instance)
    elif isinstance(executor_factory_instance,
                    reference_executor.ReferenceExecutor):
        # TODO(b/148233458): ReferenceExecutor inherits from ExectionContext and is
        # used as-is here. The plan is to migrate it to the new Executor base class
        # and stand it up inside a factory like all other executors.
        context = executor_factory_instance
    else:
        raise TypeError(
            '`set_default_executor` expects either an '
            '`executor_factory.ExecutorFactory` or `None` for the '
            'default context; you passed an argument of type {}.'.format(
                type(executor_factory_instance)))
    context_stack_impl.context_stack.set_default_context(context)
Exemplo n.º 2
0
def set_default_executor(executor=None):
    """Places an `executor`-backed execution context at the top of the stack.

  Args:
    executor: Either an instance of `executor_base.Executor`, a factory function
      returning such executors, or `None`. If `executor` is a factory function,
      the constructed context will infer the number of clients from the data it
      is passed, if possible. If `None`, causes the default reference executor
      to be installed (as is the default).
  """
    # TODO(b/140112504): Follow up here when we implement the ExecutorFactory
    # interface.
    if isinstance(executor, executor_base.Executor):
        context = execution_context.ExecutionContext(lambda x: executor)
    elif callable(executor):
        context = execution_context.ExecutionContext(executor)
    else:
        py_typecheck.check_none(executor)
        context = None
    context_stack_impl.context_stack.set_default_context(context)
Exemplo n.º 3
0
 def wrapped_fn(self, executor):
   """Install a particular execution context before running `fn`."""
   # Executors inheriting from `executor_base.Executor` will need to be
   # wrapped in an execution context. The `ReferenceExecutor` is special and
   # inherits from `context_base.Context`, so we don't wrap.
   if not isinstance(executor, context_base.Context):
     context = execution_context.ExecutionContext(executor)
   else:
     context = executor
   with context_stack_impl.context_stack.install(context):
     fn(self)
Exemplo n.º 4
0
def set_default_executor(executor=None):
    """Places an `executor`-backed execution context at the top of the stack.

  Args:
    executor: Either an instance of `executor_base.Executor`, or `None` which
      causes the default reference executor to be installed (as is the default).
  """
    if executor is not None:
        py_typecheck.check_type(executor, executor_base.Executor)
        context = execution_context.ExecutionContext(executor)
    else:
        context = None
    context_stack_impl.context_stack.set_default_context(context)
Exemplo n.º 5
0
def set_default_executor(executor_factory_instance=None):
    """Places an `executor`-backed execution context at the top of the stack.

  Args:
    executor_factory_instance: An instance of
      `executor_factory.ExecutorFactory`, or `None` for the default executor.
  """
    if executor_factory_instance is None:
        context = None
    elif isinstance(executor_factory_instance,
                    executor_factory.ExecutorFactory):
        context = execution_context.ExecutionContext(executor_factory_instance)
    else:
        raise TypeError(
            '`set_default_executor` expects either an '
            '`executor_factory.ExecutorFactory` or `None` for the '
            'default context; you passed an argument of type {}.'.format(
                type(executor_factory_instance)))
    context_stack_impl.context_stack.set_default_context(context)
Exemplo n.º 6
0
def _test_ctx():
    return execution_context.ExecutionContext(eager_executor.EagerExecutor())
Exemplo n.º 7
0
def _make_default_context():
    return execution_context.ExecutionContext(
        executor_stacks.create_local_executor())
Exemplo n.º 8
0
def _test_ctx(num_clients=None):
  return execution_context.ExecutionContext(
      executor_stacks.create_local_executor(num_clients))
Exemplo n.º 9
0
def _test_ctx(num_clients=None):
    return execution_context.ExecutionContext(
        executor_stacks.local_executor_factory(num_clients))
Exemplo n.º 10
0
def _make_default_context():
    return execution_context.ExecutionContext(
        executor_stacks.local_executor_factory())