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.


This module is inspired by werkzeug.local module but only things we actually need are left.


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


Under the hood it is an alias of greenlet.getcurrent() function if it is present. Or it will be aliased to thread.get_ident() or dummy_thread.get_ident() that both are a part of standard if greenlet 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-in dict objects.

  • 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