From 6a027bf11e756c57ab76f81d55fc9c26eb555bb2 Mon Sep 17 00:00:00 2001 From: Stan Lagun Date: Thu, 30 Apr 2015 15:21:28 +0300 Subject: [PATCH] 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 --- murano/dsl/helpers.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/murano/dsl/helpers.py b/murano/dsl/helpers.py index 47fd022b..4917fef4 100644 --- a/murano/dsl/helpers.py +++ b/murano/dsl/helpers.py @@ -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):