[pytango] 21/25: Add asyncio support for proxies

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


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

sbodomerle-guest pushed a commit to tag v8.1.9
in repository pytango.

commit c4dbc96290c3e30291466c421f075cbbaa75cfec
Author: Vincent Michel <vincent.michel at maxlab.lu.se>
Date:   Tue Aug 9 11:38:06 2016 +0200

    Add asyncio support for proxies
---
 src/boost/python/attribute_proxy.py | 56 ++++++++++++++++++-------------------
 src/boost/python/device_proxy.py    |  7 +++--
 2 files changed, 33 insertions(+), 30 deletions(-)

diff --git a/src/boost/python/attribute_proxy.py b/src/boost/python/attribute_proxy.py
index f8461f9..0d792b6 100644
--- a/src/boost/python/attribute_proxy.py
+++ b/src/boost/python/attribute_proxy.py
@@ -13,12 +13,12 @@
 This is an internal PyTango module. It completes the binding of
 :class:`PyTango.AttributeProxy`.
 
-To access these members use directly :mod:`PyTango` module and NOT 
+To access these members use directly :mod:`PyTango` module and NOT
 PyTango.attribute_proxy.
 """
 
 __all__ = [ "AttributeProxy", "attribute_proxy_init", "get_attribute_proxy" ]
-            
+
 __docformat__ = "restructuredtext"
 
 import collections
@@ -27,7 +27,7 @@ from ._PyTango import StdStringVector, DbData, DbDatum, DeviceProxy
 from ._PyTango import __AttributeProxy as _AttributeProxy
 from .utils import seq_2_StdStringVector, seq_2_DbData, DbData_2_dict
 from .utils import is_pure_str, is_non_str_seq
-from .green import result, submit, get_green_mode
+from .green import result, submit, get_green_mode, get_wait_default_value
 
 
 def get_attribute_proxy(*args, **kwargs):
@@ -36,12 +36,12 @@ def get_attribute_proxy(*args, **kwargs):
     get_attribute_proxy(self, device_proxy, attr_name, green_mode=None, wait=True, timeout=True) -> AttributeProxy
 
     Returns a new :class:`~PyTango.AttributeProxy`.
-    There is no difference between using this function and the direct 
+    There is no difference between using this function and the direct
     :class:`~PyTango.AttributeProxy` constructor if you use the default kwargs.
-     
+
     The added value of this function becomes evident when you choose a green_mode
     to be *Futures* or *Gevent*. The AttributeProxy constructor internally makes some
-    network calls which makes it *slow*. By using one of the *green modes* as 
+    network calls which makes it *slow*. By using one of the *green modes* as
     green_mode you are allowing other python code to be executed in a cooperative way.
 
     :param full_attr_name: the full name of the attribute
@@ -70,29 +70,29 @@ def get_attribute_proxy(*args, **kwargs):
         else if green_mode is Gevent:
             :class:`gevent.event.AsynchResult`
     :throws:
-        * a *DevFailed* if green_mode is Synchronous or wait is True 
+        * a *DevFailed* if green_mode is Synchronous or wait is True
           and there is an error creating the attribute.
         * a *concurrent.futures.TimeoutError* if green_mode is Futures,
           wait is False, timeout is not None and the time to create the attribute
-          has expired.                            
+          has expired.
         * a *gevent.timeout.Timeout* if green_mode is Gevent, wait is False,
           timeout is not None and the time to create the attribute has expired.
-    
+
     New in PyTango 8.1.0
     """
     # we cannot use the green wrapper because it consumes the green_mode and we
     # want to forward it to the DeviceProxy constructor
     green_mode = kwargs.get('green_mode', get_green_mode())
-    wait = kwargs.pop('wait', True)
+    wait = kwargs.pop('wait', get_wait_default_value(green_mode))
     timeout = kwargs.pop('timeout', None)
-    
+
     d = submit(green_mode, AttributeProxy, *args, **kwargs)
     return result(d, green_mode, wait=wait, timeout=timeout)
 
 def __AttributeProxy__get_property(self, propname, value=None):
     """
     get_property(self, propname, value) -> DbData
-    
+
             Get a (list) property(ies) for an attribute.
 
             This method accepts the following types as propname parameter:
@@ -155,7 +155,7 @@ def __AttributeProxy__get_property(self, propname, value=None):
 def __AttributeProxy__put_property(self, value):
     """
     put_property(self, value) -> None
-    
+
             Insert or update a list of properties for this attribute.
             This method accepts the following types as value parameter:
             1. PyTango.DbDatum - single property data to be inserted
@@ -208,10 +208,10 @@ def __AttributeProxy__put_property(self, value):
 def __AttributeProxy__delete_property(self, value):
     """
     delete_property(self, value) -> None
-    
+
         Delete a the given of properties for this attribute.
         This method accepts the following types as value parameter:
-        
+
             1. string [in] - single property to be deleted
             2. PyTango.DbDatum [in] - single property data to be deleted
             3. PyTango.DbData [in] - several property data to be deleted
@@ -221,7 +221,7 @@ def __AttributeProxy__delete_property(self, value):
                (values are ignored)
             7. dict<str, DbDatum> [in] - several DbDatum.name are property names
                to be deleted (keys are ignored)
-        
+
         Parameters :
             - value : can be one of the following:
 
@@ -234,7 +234,7 @@ def __AttributeProxy__delete_property(self, value):
                    (values are ignored)
                 7. dict<str, DbDatum> [in] - several DbDatum.name are property
                    names to be deleted (keys are ignored)
-        
+
         Return     : None
 
         Throws     : ConnectionFailed, CommunicationFailed
@@ -277,10 +277,10 @@ class AttributeProxy(object):
     """
         AttributeProxy is the high level Tango object which provides the
         client with an easy-to-use interface to TANGO attributes.
-        
+
         To create an AttributeProxy, a complete attribute name must be set
         in the object constructor.
-        
+
         Example:
             att = AttributeProxy("tango/tangotest/1/long_scalar")
 
@@ -298,11 +298,11 @@ class AttributeProxy(object):
     def get_device_proxy(self):
         """
         get_device_proxy(self) -> DeviceProxy
-        
+
                 A method which returns the device associated to the attribute
-        
+
             Parameters : None
-            
+
             Return     : (DeviceProxy)
         """
         return self.__dev_proxy
@@ -310,9 +310,9 @@ class AttributeProxy(object):
     def name(self):
         """
         name(self) -> str
-            
+
                 Returns the attribute name
-                
+
             Parameters : None
             Return     : (str) with the attribute name
         """
@@ -363,7 +363,7 @@ def __init_AttributeProxy(doc=True):
     _AttributeProxy.get_property        = __AttributeProxy__get_property
     _AttributeProxy.put_property        = __AttributeProxy__put_property
     _AttributeProxy.delete_property     = __AttributeProxy__delete_property
-    
+
     # General methods
     #AttributeProxy.name                manually defined
     AttributeProxy.status               = _method_device('status', doc=doc)
@@ -371,16 +371,16 @@ def __init_AttributeProxy(doc=True):
     AttributeProxy.ping                 = _method_device('ping', doc=doc)
     AttributeProxy.get_transparency_reconnection=_method_device('get_transparency_reconnection', doc=doc)
     AttributeProxy.set_transparency_reconnection=_method_device('set_transparency_reconnection', doc=doc)
-    
+
     # Property methods
     AttributeProxy.get_property         = _method_attribute('get_property', doc=doc)
     AttributeProxy.put_property         = _method_attribute('put_property', doc=doc)
     AttributeProxy.delete_property      = _method_attribute('delete_property', doc=doc)
-    
+
     # Attribute methods
     AttributeProxy.get_config           = _method_dev_and_name('get_attribute_config', doc=doc)
     AttributeProxy.set_config           = _method_device('set_attribute_config', doc=doc)
-    
+
     AttributeProxy.write                = _method_dev_and_name('write_attribute', doc=doc)
     AttributeProxy.read                 = _method_dev_and_name('read_attribute', doc=doc)
     AttributeProxy.write_read           = _method_dev_and_name('write_read_attribute', doc=doc)
diff --git a/src/boost/python/device_proxy.py b/src/boost/python/device_proxy.py
index bd43fb7..ade5d23 100644
--- a/src/boost/python/device_proxy.py
+++ b/src/boost/python/device_proxy.py
@@ -32,7 +32,9 @@ from .utils import is_pure_str, is_non_str_seq, is_integer
 from .utils import seq_2_StdStringVector, StdStringVector_2_seq
 from .utils import seq_2_DbData, DbData_2_dict
 from .utils import document_method as __document_method
-from .green import result, submit, green, green_cb, get_green_mode, get_event_loop
+
+from .green import result, submit, green, green_cb
+from .green import get_green_mode, get_event_loop, get_wait_default_value
 
 _UNSUBSCRIBE_LIFETIME = 60
 
@@ -93,7 +95,7 @@ def get_device_proxy(*args, **kwargs):
     # we cannot use the green wrapper because it consumes the green_mode and we
     # want to forward it to the DeviceProxy constructor
     green_mode = kwargs.get('green_mode', get_green_mode())
-    wait = kwargs.pop('wait', True)
+    wait = kwargs.pop('wait', get_wait_default_value(green_mode))
     timeout = kwargs.pop('timeout', None)
 
     # make sure the event loop is initialized
@@ -129,6 +131,7 @@ def __DeviceProxy__init__(self, *args, **kwargs):
     self.__dict__['_pending_unsubscribe'] = {}
     executors[GreenMode.Futures] = kwargs.pop('executor', None)
     executors[GreenMode.Gevent] = kwargs.pop('threadpool', None)
+    executors[GreenMode.Asyncio] = kwargs.pop('asyncio_executor', None)
     return DeviceProxy.__init_orig__(self, *args, **kwargs)
 
 def __DeviceProxy__get_green_mode(self):

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