Skip to content

Threading Module

A module with threading related utilities

ContextLocal(name, default=None)

Bases: Generic[T]

A context local value holder

get()

return the current value or invoke the optional factory to compute one

Returns:

Type Description
Optional[T]

Optional[T]: the value associated with the current thread

reset(token)

clear the value in the current thread

Parameters:

Name Type Description Default
token

the token to clear

required

set(value)

set a value in the current thread

Parameters:

Name Type Description Default
value Optional[T]

the value

required

Returns:

Type Description
Any

a token that can be used as an argument to reset

ThreadLocal(default_factory=None)

Bases: Generic[T]

A thread local value holder

clear()

clear the value in the current thread

get()

return the current value or invoke the optional factory to compute one

Returns:

Type Description
Optional[T]

Optional[T]: the value associated with the current thread

set(value)

set a value in the current thread

Parameters:

Name Type Description Default
value T

the value

required