1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 from threading import RLock
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31 NAME = 'gofer'
35 """
36 Singleton metaclass
37 usage: __metaclass__ = Singleton
38 """
39
40 __inst = {}
41 __mutex = RLock()
42
43 @classmethod
46
47 @classmethod
49 key = []
50 for x in t:
51 if isinstance(x, (str,int,float)):
52 key.append(x)
53 for k in sorted(d.keys()):
54 v = d[k]
55 if isinstance(v, (str,int,float)):
56 key.append((k,v))
57 return repr(key)
58
59 @classmethod
66
79
80 @classmethod
87
88 @classmethod
91
92 @classmethod
95
98 """
99 Decorator that provides reentrant method invocation
100 using the object's mutex. The object must have a private
101 RLock attribute named __mutex. Intended only for instance
102 methods that have a method body that can be safely mutexed
103 in it's entirety to prevent deadlock senarios.
104 """
105 def sfn(*args, **kwargs):
106 inst = args[0]
107 cn = inst.__class__.__name__
108 mutex = getattr(inst, '_%s__mutex' % cn)
109 mutex.acquire()
110 try:
111 return fn(*args, **kwargs)
112 finally:
113 mutex.release()
114 return sfn
115
117 """
118 Decorator that provides reentrant method invocation
119 using the object's mutex. The object must have a private
120 RLock attribute named __mutex. Intended only for instance
121 methods that have a method body that can be safely mutexed
122 in it's entirety to prevent deadlock senarios.
123 """
124 def sfn(*args, **kwargs):
125 inst = args[0]
126 cn = inst.__class__.__name__
127 mutex = getattr(inst, '_%s__condition' % cn)
128 mutex.acquire()
129 try:
130 return fn(*args, **kwargs)
131 finally:
132 mutex.release()
133 return sfn
134