#!/usr/bin/env python################################################################################# This file is part of Sardana### http://www.sardana-controls.org/### Copyright 2011 CELLS / ALBA Synchrotron, Bellaterra, Spain### Sardana is free software: you can redistribute it and/or modify# it under the terms of the GNU Lesser General Public License as published by# the Free Software Foundation, either version 3 of the License, or# (at your option) any later version.### Sardana is distributed in the hope that it will be useful,# but WITHOUT ANY WARRANTY; without even the implied warranty of# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the# GNU Lesser General Public License for more details.### You should have received a copy of the GNU Lesser General Public License# along with Sardana. If not, see <http://www.gnu.org/licenses/>.################################################################################"""This module contains the function to access sardana thread pool"""__all__=["get_thread_pool"]__docformat__="restructuredtext"importthreadingfromtaurus.core.util.threadpoolimportThreadPool,Worker__thread_pool_lock=threading.Lock()__thread_pool=NoneclassOmniWorker(Worker):defrun(self):try:importtangoexceptImportError:Worker.run(self)# Tango is not thread safe when using threading.Thread. One must# use omni threads instead. This was confirmed for parallel# event subscriptions in PyTango#307. Use EnsureOmniThread introduced# in PyTango#327 whenever available.else:ifhasattr(tango,"EnsureOmniThread"):withtango.EnsureOmniThread():Worker.run(self)else:importtaurustaurus.warning("Your Sardana system is affected by bug ""tango-controls/pytango#307. Please use ""PyTango with tango-controls/pytango#327.")Worker.run(self)
[docs]defget_thread_pool()->ThreadPool:"""Returns the global pool of threads for Sardana :return: the global pool of threads object """global__thread_poolglobal__thread_pool_lockwith__thread_pool_lock:if__thread_poolisNone:# protect older versions of Taurus (without the worker_cls# argument) remove it whenever we bump Taurus dependencytry:__thread_pool=ThreadPool(name="SardanaTP",Psize=10,worker_cls=OmniWorker)exceptTypeError:importtaurustaurus.warning("Your Sardana system is affected by bug ""tango-controls/pytango#307. Please use ""Taurus with taurus-org/taurus#1081.")__thread_pool=ThreadPool(name="SardanaTP",Psize=10)return__thread_pool