sider.threadlocal
— Thread locals¶
This module provides a small thread/greenlet local object.
Why we don’t simply use the built-in threading.local
is there’s the case of using greenlet
, the non-standard
but de facto standard coroutine module for Python, in real world.
(For example, widely used networking libraries like gevent
or eventlet
heavily use greenlet
.)
LocalDict
which this module offers isn’t aware of only
threads but including greenlets.
Note
This module is inspired by werkzeug.local
module but
only things we actually need are left.
-
sider.threadlocal.
get_ident
()¶ Gets the object that can identify of the current thread/greenlet. It can return an object that can be used as dictionary keys.
Returns: a something that can identify of the current thread or greenlet Note
Under the hood it is an alias of
greenlet.getcurrent()
function if it is present. Or it will be aliased tothread.get_ident()
ordummy_thread.get_ident()
that both are a part of standard ifgreenlet
module is not present.However that’s all only an implementation detail and so it may changed in the future. Client codes that use
sider.threadlocal.get_ident()
have to be written on only assumptions that it guarantees: it returns an object that identify of the current thread/greenlet and be used as dictionary keys.
-
class
sider.threadlocal.
LocalDict
(mapping=[], **keywords)¶ A thread/greenlet-local dictionary. It implements
collections.MutableMapping
protocol and so behaves almost like built-indict
objects.Parameters: - mapping (
collections.Mapping
,collections.Iterable
) – the initial items. all locals have the same this initial items - **keywords – the initial keywords. all locals have the same this initial items
- mapping (