[pytango] 99/122: Patch all gevent ThreadPool.spawn calls if gevent version under 1.1.0

Sandor Bodo-Merle sbodomerle-guest at moszumanska.debian.org
Thu Sep 28 19:18:23 UTC 2017


This is an automated email from the git hooks/post-receive script.

sbodomerle-guest pushed a commit to tag v9.2.1
in repository pytango.

commit dae691b1fef71af2b2ebc98a1101dd4f8db9b593
Author: antdup <antione.dupre at maxiv.lu.se>
Date:   Wed Jan 11 16:50:47 2017 +0100

    Patch all gevent ThreadPool.spawn calls if gevent version under 1.1.0
---
 tango/green.py        |  3 ---
 tango/tango_gevent.py | 30 ++++++++++++++++++++++++------
 2 files changed, 24 insertions(+), 9 deletions(-)

diff --git a/tango/green.py b/tango/green.py
index 6933a12..909fc29 100644
--- a/tango/green.py
+++ b/tango/green.py
@@ -217,8 +217,6 @@ def get_object_submitter(obj, green_mode=None):
     if executor is None:
         executor = get_executor(green_mode)
     # Get submitter
-    if green_mode == GreenMode.Gevent:
-        return executor.spawn
     return executor.submit
 
 
@@ -267,7 +265,6 @@ def green(fn):
 
         # return the proper result
         return waiter(ret, timeout=timeout) if wait else ret
-
     return greener
 
 
diff --git a/tango/tango_gevent.py b/tango/tango_gevent.py
index d2739ac..9958e8c 100644
--- a/tango/tango_gevent.py
+++ b/tango/tango_gevent.py
@@ -18,9 +18,18 @@ import six
 __all__ = ["get_global_threadpool", "get_global_executor",
            "get_event_loop", "submit", "spawn", "wait"]
 
+
 def get_global_threadpool():
     import gevent
-    return gevent.get_hub().threadpool
+    thread_pool = gevent.get_hub().threadpool
+    # before gevent-1.1.0, patch the spawn method to propagate exception raised
+    # in the loop to the AsyncResult.
+    if gevent.version_info[0] <= 1 and gevent.version_info[1] < 1:
+        thread_pool.submit = patched_spawn
+    else:
+        thread_pool.submit = thread_pool.spawn
+    return thread_pool
+
 
 class ExceptionWrapper:
     def __init__(self, exception, error_string, tb):
@@ -28,6 +37,7 @@ class ExceptionWrapper:
         self.error_string = error_string
         self.tb = tb
 
+
 class wrap_errors(object):
     def __init__(self, func):
         """Make a new function from `func', such that it catches all exceptions
@@ -51,28 +61,35 @@ class wrap_errors(object):
     def __getattr__(self, item):
         return getattr(self.func, item)
 
+
 def get_with_exception(g, block=True, timeout=None):
     result = g._get(block, timeout)
     if isinstance(result, ExceptionWrapper):
         # raise the exception using the caller context
-        six.reraise(result.exception, result.error_string,result.tb)
+        six.reraise(result.exception, result.error_string, result.tb)
     else:
         return result
 
-def spawn(fn, *args, **kwargs):
-    # the gevent threadpool do not raise exception with asyncresults, we have to wrap it
+
+def patched_spawn(fn, *args, **kwargs):
+    # the gevent threadpool do not raise exception with asyncresults,
+    # we have to wrap it
     fn = wrap_errors(fn)
     g = get_global_threadpool().spawn(fn, *args, **kwargs)
     g._get = g.get
     g.get = types.MethodType(get_with_exception, g)
     return g
 
-get_global_executor = get_global_threadpool
 
-submit = spawn
+def spawn(fn, *args, **kwargs):
+    return get_global_threadpool().submit(fn, *args, **kwargs)
 
+
+get_global_executor = get_global_threadpool
+submit = spawn
 __event_loop = None
 
+
 def get_event_loop():
     global __event_loop
     if __event_loop is None:
@@ -98,5 +115,6 @@ def get_event_loop():
         __event_loop.submit = submit
     return __event_loop
 
+
 def wait(greenlet, timeout=None):
     return greenlet.get(timeout=timeout)

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-science/packages/pytango.git



More information about the debian-science-commits mailing list