Skip to main content

LocalManager

Local objects cannot manage themselves.

For that you need a local manager. You can pass a local manager multiple locals or add them later by appending them to manager.locals. Every time the manager cleans up, it will clean up all the data left in the locals for this context.

Attributes

AttributeTypeDescription
localslist = []A list of local objects that this manager is responsible for cleaning up at the end of a context.
ident_funccallable = get_identThe function used to determine the current context identifier for all managed local objects.

Constructor

Signature

def LocalManager(
locals: list or Local = None,
ident_func: callable = None
)

Parameters

NameTypeDescription
localslist or Local = NoneA single Local object or an iterable of Local objects to be managed.
ident_funccallable = NoneA function used to get the current context identifier. Defaults to get_ident if not provided.

Methods


get_ident()

@classmethod
def get_ident() - > integer

Return context identifier. This is the identifier the local objects use internally for this context. You cannot override this method to change the behavior but use it to link other context local objects (such as SQLAlchemy's scoped sessions) to the Werkzeug locals.

Returns

TypeDescription
integerThe unique identifier for the current execution context, typically a thread or greenlet ID.

cleanup()

@classmethod
def cleanup()

Manually clean up the data in the locals for this context. Call this at the end of the request or use make_middleware().