[pytango] 107/122: Fix asyncio executor on the server side

Sandor Bodo-Merle sbodomerle-guest at moszumanska.debian.org
Thu Sep 28 19:18:24 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 995db7665bec4afa752202f53b70cb2ac05c7041
Author: Vincent Michel <vincent.michel at maxlab.lu.se>
Date:   Mon Jan 16 17:49:53 2017 +0100

    Fix asyncio executor on the server side
---
 tango/server.py | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/tango/server.py b/tango/server.py
index 9a4789d..1b7f0b1 100644
--- a/tango/server.py
+++ b/tango/server.py
@@ -1616,6 +1616,7 @@ def _create_gevent_worker():
 
 def _create_asyncio_worker():
     import concurrent.futures
+    from threading import get_ident
 
     try:
         import asyncio
@@ -1635,11 +1636,10 @@ def _create_asyncio_worker():
             """Initialize the executor with a given loop."""
             self.loop = loop or asyncio.get_event_loop()
 
-        def submit(self, fn, *args, **kwargs):
-            """Schedule the callable fn, to be executed as fn(*args **kwargs).
+        def submit(self, corofn, *args, **kwargs):
+            """Schedule a coroutine, to be executed as corofn(*args **kwargs).
             Return a Future representing the execution of the callable."""
-            corofn = asyncio.coroutine(lambda: fn(*args, **kwargs))
-            return run_coroutine_threadsafe(corofn(), loop)
+            return run_coroutine_threadsafe(corofn(*args, **kwargs), self.loop)
 
         def run_in_thread(self, func, *args, **kwargs):
             """Schedule a blocking callback."""
@@ -1664,7 +1664,10 @@ def _create_asyncio_worker():
 
         def execute(self, fn, *args, **kwargs):
             """Execute the callable fn as fn(*args **kwargs)."""
-            return self.submit(fn, *args, **kwargs).result()
+            corofn = asyncio.coroutine(fn)
+            if self.loop._thread_id == get_ident():
+                return corofn(*args, **kwargs)
+            return self.submit(corofn, *args, **kwargs).result()
 
     try:
         loop = asyncio.get_event_loop()

-- 
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