1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 """
17 Miscellaneous utilities; these should be imported from C{buildbot.util}, not
18 directly from this module.
19 """
20
21 from twisted.python import log
22 from twisted.internet import defer
23
25 def decorator(fn):
26 def wrapper(*args, **kwargs):
27 lock = lock_or_attr
28 if isinstance(lock, basestring):
29 lock = getattr(args[0], lock)
30 d = lock.acquire()
31 d.addCallback(lambda _ : fn(*args, **kwargs))
32 def release(val):
33 lock.release()
34 return val
35 d.addBoth(release)
36 return d
37 return wrapper
38 return decorator
39
42 self.method = method
43 self.running = False
44 self.pending_deferreds = []
45
47 d = defer.Deferred()
48 self.pending_deferreds.append(d)
49 if not self.running:
50 self.start()
51 return d
52
54 self.running = True
55 invocation_deferreds = self.pending_deferreds
56 self.pending_deferreds = []
57 d = self.method()
58 d.addErrback(log.err, 'in invocation of %r' % (self.method,))
59
60 def notify_callers(_):
61 for d in invocation_deferreds:
62 d.callback(None)
63 d.addCallback(notify_callers)
64
65 def next(_):
66 self.running = False
67 if self.pending_deferreds:
68 self.start()
69 else:
70 self._quiet()
71 d.addBoth(next)
72
74 pass
75