Beispiel #1
0
    except:
        # catch all, py.* fails with so many different errors.
        get_current_greenlet = int
try:
    from six.moves._thread import get_ident as get_current_thread, allocate_lock
except ImportError: # pragma: no cover
    from six.moves._dummy_thread import get_ident as get_current_thread, allocate_lock


# get the best ident function.  if greenlets are not installed we can
# safely just use the builtin thread function and save a python methodcall
# and the cost of calculating a hash.
if get_current_greenlet is int: # pragma: no cover
    get_ident = get_current_thread
else:
    get_ident = lambda: (get_current_thread(), get_current_greenlet())


class Local(object):
    """A container for thread-local objects.

    Attributes are assigned or retrieved using the current thread.
    """

    __slots__ = ('__storage__', '__lock__')

    def __init__(self):
        object.__setattr__(self, '__storage__', {})
        object.__setattr__(self, '__lock__', allocate_lock())

    def __iter__(self):
Beispiel #2
0
 def get_ident():
     return get_current_thread(), get_current_greenlet()
Beispiel #3
0
 def get_ident():
     return get_current_thread(), get_current_greenlet()