An asynchronous method call may return a result before the actual method
call has returned the sequence number, so use a lock to ensure this is
handled correctly. Also, correctly ignore results that don't match an
expected sequence number - e.g. if they come from a previous call that has
already timed out.
Signed-off-by: Zane Bitter <zbitter(a)redhat.com>
---
src/python/matahari/core.py | 14 +++++++++-----
1 files changed, 9 insertions(+), 5 deletions(-)
diff --git a/src/python/matahari/core.py b/src/python/matahari/core.py
index e79b24a..bcb1597 100644
--- a/src/python/matahari/core.py
+++ b/src/python/matahari/core.py
@@ -177,16 +177,20 @@ class Manager(object):
results = [None] * len(objs)
seqs = []
event = threading.Event()
+ seqlock = threading.Lock()
def recv_response(seq, response):
- i = seqs.index(seq)
- results[i] = response
- if None not in results:
- event.set()
+ with seqlock:
+ i = seqs.index(seq)
+ if i >= 0:
+ results[i] = response
+ if None not in results:
+ event.set()
self._async.handle_method_responses(recv_response)
for o in objs:
m = getattr(o, method)
- seqs.append(m(*args, _async=True, **kwargs))
+ with seqlock:
+ seqs.append(m(*args, _async=True, **kwargs))
event.wait(TIMEOUT)
return tuple(results)
Show replies by date