Revision 81c60832 kamaki/clients/__init__.py
b/kamaki/clients/__init__.py | ||
---|---|---|
369 | 369 |
return [] |
370 | 370 |
return threadlist |
371 | 371 |
|
372 |
def async_run(self, method, kwarg_list): |
|
373 |
"""Fire threads of operations |
|
374 |
|
|
375 |
:param method: the method to run in each thread |
|
376 |
|
|
377 |
:param kwarg_list: (list of dicts) the arguments to pass in each method |
|
378 |
call |
|
379 |
|
|
380 |
:returns: (list) the results of each method call w.r. to the order of |
|
381 |
kwarg_list |
|
382 |
""" |
|
383 |
flying, results = {}, {} |
|
384 |
self._init_thread_limit() |
|
385 |
for index, kwargs in enumerate(kwarg_list): |
|
386 |
self._watch_thread_limit(flying.values()) |
|
387 |
flying[index] = SilentEvent(method=method, **kwargs) |
|
388 |
flying[index].start() |
|
389 |
unfinished = {} |
|
390 |
for key, thread in flying.items(): |
|
391 |
if thread.isAlive(): |
|
392 |
unfinished[key] = thread |
|
393 |
elif thread.exception: |
|
394 |
print 'HERE IS AN EXCEPTION MK?' |
|
395 |
raise thread.exception |
|
396 |
else: |
|
397 |
results[key] = thread.value |
|
398 |
print 'NO EXCEPTION', thread.value |
|
399 |
flying = unfinished |
|
400 |
sendlog.info('- - - wait for threads to finish') |
|
401 |
for key, thread in flying.items(): |
|
402 |
if thread.isAlive(): |
|
403 |
thread.join() |
|
404 |
elif thread.exception: |
|
405 |
print 'HERE IS AN EXCEPTION MK-2?' |
|
406 |
raise thread.exception |
|
407 |
results[key] = thread.value |
|
408 |
print 'NO EXCEPTION-2', thread.value |
|
409 |
return results.values() |
|
410 |
|
|
372 | 411 |
def _raise_for_status(self, r): |
373 | 412 |
log.debug('raise err from [%s] of type[%s]' % (r, type(r))) |
374 | 413 |
status_msg = getattr(r, 'status', None) or '' |
Also available in: Unified diff