LangChain Reference home pageLangChain ReferenceLangChain Reference
  • GitHub
  • Main Docs
Deep Agents
LangChain
LangGraph
Integrations
LangSmith
  • Overview
  • Graphs
  • Functional API
  • Pregel
  • Checkpointing
  • Storage
  • Caching
  • Types
  • Runtime
  • Config
  • Errors
  • Constants
  • Channels
  • Agents
LangGraph CLI
LangGraph SDK
LangGraph Supervisor
LangGraph Swarm
⌘I

LangChain Assistant

Ask a question to get started

Enter to send•Shift+Enter new line

Menu

OverviewGraphsFunctional APIPregelCheckpointingStorageCachingTypesRuntimeConfigErrorsConstantsChannelsAgents
LangGraph CLI
LangGraph SDK
LangGraph Supervisor
LangGraph Swarm
Language
Theme
Pythonlanggraphpregel_executorBackgroundExecutor
Class●Since v0.6

BackgroundExecutor

A context manager that runs sync tasks in the background. Uses a thread pool executor to delegate tasks to separate threads. On exit,

  • cancels any (not yet started) tasks with __cancel_on_exit__=True
  • waits for all tasks to finish
  • re-raises the first exception from tasks with __reraise_on_exit__=True
Copy
BackgroundExecutor(
    self,
    config: RunnableConfig,
)

Bases

AbstractContextManager

Constructors

constructor
__init__
NameType
configRunnableConfig

Attributes

attribute
stack
attribute
executor
attribute
tasks: dict[concurrent.futures.Future, tuple[bool, bool]]

Methods

method
submit
method
done

Remove the task from the tasks dict when it's done.

View source on GitHub