3 from eventlet import greenthread
5 __all__ = ['get_ident', 'local']
9 """ Returns ``id()`` of current greenlet. Useful for debugging."""
10 return id(greenthread.getcurrent())
13 # the entire purpose of this class is to store off the constructor
14 # arguments in a local variable without calling __init__ directly
15 class _localbase(object):
16 __slots__ = '_local__args', '_local__greens'
18 def __new__(cls, *args, **kw):
19 self = object.__new__(cls)
20 object.__setattr__(self, '_local__args', (args, kw))
21 object.__setattr__(self, '_local__greens', weakref.WeakKeyDictionary())
22 if (args or kw) and (cls.__init__ is object.__init__):
23 raise TypeError("Initialization arguments are not supported")
28 greens = object.__getattribute__(thrl, '_local__greens')
29 # until we can store the localdict on greenlets themselves,
30 # we store it in _local__greens on the local object
31 cur = greenthread.getcurrent()
33 # must be the first time we've seen this greenlet, call __init__
36 if cls.__init__ is not object.__init__:
37 args, kw = object.__getattribute__(thrl, '_local__args')
38 thrl.__init__(*args, **kw)
39 object.__setattr__(thrl, '__dict__', greens[cur])
42 class local(_localbase):
43 def __getattribute__(self, attr):
45 return object.__getattribute__(self, attr)
47 def __setattr__(self, attr, value):
49 return object.__setattr__(self, attr, value)
51 def __delattr__(self, attr):
53 return object.__delattr__(self, attr)