[pytango] 250/483: implement feature request #88: Implement Util::server_set_event_loop method in python

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


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

sbodomerle-guest pushed a commit to annotated tag bliss_8.10
in repository pytango.

commit 89b28eca2fde61b0f600f5f0ad6906baf3afe44e
Author: tiagocoutinho <tiagocoutinho at 4e9c00fd-8f2e-0410-aa12-93ce3db5e235>
Date:   Tue May 14 20:02:57 2013 +0000

    implement feature request #88: Implement Util::server_set_event_loop method in python
    
    git-svn-id: http://svn.code.sf.net/p/tango-cs/code/bindings/PyTango/trunk@22671 4e9c00fd-8f2e-0410-aa12-93ce3db5e235
---
 doc/revision.rst                    |  7 +++++--
 src/boost/cpp/server/tango_util.cpp | 27 +++++++++++++++++++++++++
 src/boost/python/pyutil.py          | 40 ++++++++++++++++++++++++++++++++++++-
 3 files changed, 71 insertions(+), 3 deletions(-)

diff --git a/doc/revision.rst b/doc/revision.rst
index 16a8771..9acfe9c 100644
--- a/doc/revision.rst
+++ b/doc/revision.rst
@@ -69,7 +69,7 @@ History of modifications:
 +----------+----------------------------------------------------------------------------------+-----------------------------------------------------+-----------------------+
 | 10/10/12 | `8.15 <http://www.tango-controls.org/static/PyTango/v802/doc/html/index.html>`_  | Update to PyTango 8.0.2                             | T\. Coutinho          |
 +----------+----------------------------------------------------------------------------------+-----------------------------------------------------+-----------------------+
-| --/--/12 | `8.16 <http://www.tango-controls.org/static/PyTango/v803/doc/html/index.html>`_  | Update to PyTango 8.0.3                             | T\. Coutinho          |
+| --/--/13 | `8.16 <http://www.tango-controls.org/static/PyTango/v810/doc/html/index.html>`_  | Update to PyTango 8.1.0                             | T\. Coutinho          |
 +----------+----------------------------------------------------------------------------------+-----------------------------------------------------+-----------------------+
 
 .. _version-history:
@@ -80,7 +80,10 @@ Version history
 +------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
 | version    | Changes                                                                                                                                                                      |
 +============+==============================================================================================================================================================================+
-| 8.0.3      | Bug fixes:                                                                                                                                                                   |
+| 8.1.0      | Features:                                                                                                                                                                    |
+|            |     - from sourceforge:                                                                                                                                                      |
+|            |         - `88: Implement Util::server_set_event_loop method in python <https://sourceforge.net/p/tango-cs/feature-requests/88>`_                                             |
+|            | Bug fixes:                                                                                                                                                                   |
 |            |     - from sourceforge:                                                                                                                                                      |
 |            |         - `3576353: [pytango] segfault on 'RestartServer' <https://sourceforge.net/tracker/?func=detail&aid=3576353&group_id=57612&atid=484769>`_                            |
 |            |         - `3579062: [pytango] Attribute missing methods <https://sourceforge.net/tracker/?func=detail&aid=3579062&group_id=57612&atid=484769>`_                              |
diff --git a/src/boost/cpp/server/tango_util.cpp b/src/boost/cpp/server/tango_util.cpp
index d8dc66a..506ad42 100644
--- a/src/boost/cpp/server/tango_util.cpp
+++ b/src/boost/cpp/server/tango_util.cpp
@@ -162,6 +162,32 @@ namespace PyUtil
         }
         return py_dev_list;
     }
+    
+    inline bool event_loop()
+    {
+        AutoPythonGIL guard;
+        PYTANGO_MOD
+        boost::python::object py_event_loop = pytango.attr("_server_event_loop");
+        boost::python::object py_ret = py_event_loop();
+        bool ret = boost::python::extract<bool>(py_ret);
+        return ret;
+    }
+    
+    inline void server_set_event_loop(Tango::Util& self,
+                                      boost::python::object& py_event_loop)
+    {
+        PYTANGO_MOD
+        if (py_event_loop.is_none())
+        {
+            self.server_set_event_loop(NULL);
+            pytango.attr("_server_event_loop") = py_event_loop;
+        }
+        else
+        {
+            pytango.attr("_server_event_loop") = py_event_loop;
+            self.server_set_event_loop(event_loop);
+        }
+    }
 }
 
 void init_python()
@@ -232,6 +258,7 @@ void export_util()
         .def("get_device_list_by_class", &PyUtil::get_device_list_by_class)
         .def("get_device_by_name", &PyUtil::get_device_by_name)
         .def("get_device_list", &PyUtil::get_device_list)
+        .def("server_set_event_loop", &PyUtil::server_set_event_loop)
         .def_readonly("_UseDb", &Tango::Util::_UseDb)
         .def_readonly("_FileDb", &Tango::Util::_FileDb)
         .def("init_python", init_python)
diff --git a/src/boost/python/pyutil.py b/src/boost/python/pyutil.py
index 6f71e24..862d4ed 100644
--- a/src/boost/python/pyutil.py
+++ b/src/boost/python/pyutil.py
@@ -209,7 +209,10 @@ def __Util__delete_device(self, klass_name, device_name):
     dc = dimpl.get_device_class()
     dc.device_destroyer(device_name)
 
-    
+def __Util__server_set_event_loop(self, event_loop):
+    self._server_event_loop = event_loop
+    self._server_set_event_loop()
+
 class Util(_Util):
     """
         This class is a used to store TANGO device server process data and to
@@ -691,6 +694,41 @@ def __doc_Util():
         New in PyTango 7.0.0
     """ )
     
+    document_method("server_set_event_loop", """
+    server_set_event_loop(self, event_loop) -> None
+    
+        This method registers an event loop function in a Tango server.
+        This function will be called by the process main thread in an infinite loop
+        The process will not use the classical ORB blocking event loop.
+        It is the user responsability to code this function in a way that it implements
+        some kind of blocking in order not to load the computer CPU. The following 
+        piece of code is an example of how you can use this feature::
+        
+            _LOOP_NB = 1
+            def looping():
+                global _LOOP_NB
+                print "looping", _LOOP_NB
+                time.sleep(0.1)
+                _LOOP_NB += 1
+                return _LOOP_NB > 100
+            
+            def main():
+                py = PyTango.Util(sys.argv)
+                
+                # ...
+
+                U = PyTango.Util.instance()
+                U.server_set_event_loop(looping)
+                U.server_init()
+                U.server_run()
+
+        Parameters : None
+        Return     : None
+        
+        New in PyTango 8.1.0
+    """ )
+
+            
 #    document_static_method("init_python", """
 #    init_python() -> None
 #

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