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)
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)
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)
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)
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)
def _test_ctx(): return execution_context.ExecutionContext(eager_executor.EagerExecutor())
def _make_default_context(): return execution_context.ExecutionContext( executor_stacks.create_local_executor())
def _test_ctx(num_clients=None): return execution_context.ExecutionContext( executor_stacks.create_local_executor(num_clients))
def _test_ctx(num_clients=None): return execution_context.ExecutionContext( executor_stacks.local_executor_factory(num_clients))
def _make_default_context(): return execution_context.ExecutionContext( executor_stacks.local_executor_factory())