From e4165f562335c1a63804f440f5750d34a40f05e3 Mon Sep 17 00:00:00 2001 From: Jedrzej Nowak Date: Wed, 24 Feb 2016 18:00:04 +0100 Subject: [PATCH] Workaround for TypeError in zerorpc Events.__del__ Change-Id: If9a096f8c970e6f5e7449e60327ed0a0b0546366 Closes-bug: #1549384 --- .../executors/zerorpc_executor.py | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/solar/orchestration/executors/zerorpc_executor.py b/solar/orchestration/executors/zerorpc_executor.py index 35e1e057..fee21c4d 100644 --- a/solar/orchestration/executors/zerorpc_executor.py +++ b/solar/orchestration/executors/zerorpc_executor.py @@ -12,9 +12,10 @@ # License for the specific language governing permissions and limitations # under the License. +import gevent import sys -import gevent +from functools import update_wrapper # NOTE(jnowak): this is a workaround for bug in zerorpc.gevent_zmq # it's broken on gevent patched environments and when @@ -23,6 +24,7 @@ import zmq.green as zmq if tuple(map(int, zmq.__version__.split('.'))) > (13, 0, 2): sys.modules['zmq'] = zmq else: + del sys.modules['zmq'] del zmq # NOTE(jnowak): NOQA because of workaround above (E402) @@ -32,6 +34,24 @@ from solar.core.log import log # NOQA from solar.orchestration.executors import base # NOQA +# NOTE(jnowak): this is there because of __del__ in zerorpc Events +# without that patch you may have: +# TypeError("'NoneType' object is not callable",) +# during interpreter shutdown +# see #1549384 bug for more info +def patch_events(): + def fixed_del(obj): + try: + obj.__orig_del__() + except TypeError: + pass + update_wrapper(fixed_del, zerorpc.events.Events.__del__) + zerorpc.events.Events.__orig_del__ = zerorpc.events.Events.__del__ + zerorpc.events.Events.__del__ = fixed_del + +patch_events() + + class PoolBasedPuller(zerorpc.Puller): """ImprovedPuller allows to control pool of gevent threads and track assignments of gevent threads