pselect exited on first exception

Due to eventlet bug in GreenPool implementation when first
spawned thread threw exception imap method exited immediately
without waiting for other spawned threads to accomplish.

Issue in eventlet github:
https://github.com/eventlet/eventlet/issues/232

This commits wraps executed functions so that no exception can be
raised on imap boundary and then unwraps result after execution

 Closes-Bug: #1449497

Change-Id: I0e99de8e0711071c4a009e37a58ec22761e90e6c
(cherry picked from commit 6a027bf11e)
This commit is contained in:
Stan Lagun 2015-04-30 15:21:28 +03:00
parent 68494598ef
commit fba9ed643d
1 changed files with 15 additions and 1 deletions

View File

@ -145,8 +145,22 @@ def generate_id():
def parallel_select(collection, func):
# workaround for eventlet issue 232
# https://github.com/eventlet/eventlet/issues/232
def wrapper(element):
try:
return func(element), False, None
except Exception as e:
return e, True, sys.exc_info()[2]
gpool = eventlet.greenpool.GreenPool()
return list(gpool.imap(func, collection))
result = list(gpool.imap(wrapper, collection))
try:
exception = next(t for t in result if t[1])
except StopIteration:
return map(lambda t: t[0], result)
else:
raise exception[0], None, exception[2]
def to_python_codestyle(name):