当前位置: 首页>>代码示例>>Python>>正文


Python ThreadPool.adjustPoolsize方法代码示例

本文整理汇总了Python中twisted.python.threadpool.ThreadPool.adjustPoolsize方法的典型用法代码示例。如果您正苦于以下问题:Python ThreadPool.adjustPoolsize方法的具体用法?Python ThreadPool.adjustPoolsize怎么用?Python ThreadPool.adjustPoolsize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在twisted.python.threadpool.ThreadPool的用法示例。


在下文中一共展示了ThreadPool.adjustPoolsize方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: ClockWithThreads

# 需要导入模块: from twisted.python.threadpool import ThreadPool [as 别名]
# 或者: from twisted.python.threadpool.ThreadPool import adjustPoolsize [as 别名]
class ClockWithThreads(Clock):
    """
    A testing reactor that supplies L{IReactorTime} and L{IReactorThreads}.
    """

    def __init__(self):
        super(ClockWithThreads, self).__init__()
        self._pool = ThreadPool()


    def getThreadPool(self):
        """
        Get the threadpool.
        """
        return self._pool


    def suggestThreadPoolSize(self, size):
        """
        Approximate the behavior of a 'real' reactor.
        """
        self._pool.adjustPoolsize(maxthreads=size)


    def callInThread(self, thunk, *a, **kw):
        """
        No implementation.
        """


    def callFromThread(self, thunk, *a, **kw):
        """
开发者ID:anemitz,项目名称:calendarserver,代码行数:34,代码来源:fixtures.py

示例2: __init__

# 需要导入模块: from twisted.python.threadpool import ThreadPool [as 别名]
# 或者: from twisted.python.threadpool.ThreadPool import adjustPoolsize [as 别名]
    def __init__(
            self, application, port=80, resources=None, services=None,
            loud=False):
        service.MultiService.__init__(self)

        # Create, start and add a thread pool service, which is made available
        # to our WSGIResource within HendrixResource
        threads = ThreadPool(name="Hendrix Service")

        # Testing threads 1-2-3
        threads.adjustPoolsize(3, 5)

        reactor.addSystemEventTrigger('after', 'shutdown', threads.stop)
        ThreadPoolService(threads).setServiceParent(self)

        # create the base resource and add any additional static resources
        resource = HendrixResource(reactor, threads, application, loud=loud)
        if resources:
            resources = sorted(resources, key=lambda r: r.namespace)
            for res in resources:
                if hasattr(res, 'get_resources'):
                    for sub_res in res.get_resources():
                        resource.putNamedChild(sub_res)
                else:
                    resource.putNamedChild(res)

        factory = server.Site(resource)
        # add a tcp server that binds to port=port
        main_web_tcp = TCPServer(port, factory)
        main_web_tcp.setName('main_web_tcp')
        # to get this at runtime use
        # hedrix_service.getServiceNamed('main_web_tcp')
        main_web_tcp.setServiceParent(self)

        # add any additional services
        if services:
            for srv_name, srv in services:
                srv.setName(srv_name)
                srv.setServiceParent(self)
开发者ID:SlashRoot,项目名称:hendrix,代码行数:41,代码来源:services.py

示例3: ThreadPool

# 需要导入模块: from twisted.python.threadpool import ThreadPool [as 别名]
# 或者: from twisted.python.threadpool.ThreadPool import adjustPoolsize [as 别名]
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License along
#    with this program; if not, write to the Free Software Foundation, Inc.,
#    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#

from protocol import format_string
from twisted.python.threadpool import ThreadPool
import logging
import time

logger = logging.getLogger(name='plugin')

pool = ThreadPool()
pool.adjustPoolsize(1)
pool.start()

class Plugin:
	"""
	Base class of a plugin. Use this when writing new plugins. Provides
	several methods to communicate with the clients.

	Provide at least these methods:
	- name(): String ID of the plugin. It must match the name in the client
	    counterpart.
	- message_from_client(message): Called when the client sends some data,
	    usually as a response to some request.
	"""
	def __init__(self, plugins):
		"""
开发者ID:CZ-NIC,项目名称:ucollect,代码行数:33,代码来源:plugin.py

示例4: Stats

# 需要导入模块: from twisted.python.threadpool import ThreadPool [as 别名]
# 或者: from twisted.python.threadpool.ThreadPool import adjustPoolsize [as 别名]
class Stats(object):
    """
        stats.Stats rrdtool templated poller, updater, and web frontend
    """
    
    # Our default configuration directives, if they don't
    # exist in the configuration file, they'll reflect what's here
    default_config = ImmutableDict(**dict(
        graphs = [],
        httpd_port = 8080,
        interface = '0.0.0.0',
        graph_draw_frequency = dict(
            hour = 60,
            day = 300,
            week = 300*3,
            default = 60
        ),
        wsgi_min_threads = 1,
        wsgi_max_threads = 5
    ))

    def __init__(self, instance_name):
        self.instance_name = instance_name
        self.config = Config(self.default_config)
        self.flask_app = WebApp(self)
        self.template_runner = TemplateRunner(self)
        self.active_graphs = dict()
        self.last_draw_timestamp = dict()
        self.wsgi_threadpool = ThreadPool(minthreads = self.config['wsgi_min_threads'], maxthreads=self.config['wsgi_max_threads'], name = 'wsgi_threadpool')
    
    def validate_config(self):
        """ Validates the loaded configuration. """
        c = self.config
        
        # Make sure that we have a database_path, and an image_path...
        assert 'database_path' in c
        assert 'image_path' in c
        # We should probably check if these paths exist and make them as well...
        
        # Set the default values.
        graph_draw_frequency = c['graph_draw_frequency']
        for period, interval in self.default_config['graph_draw_frequency'].iteritems():
            graph_draw_frequency.setdefault(period, interval)
        
        # A quick check to make sure that our port is an integer.
        c['httpd_port'] = int(c['httpd_port'])
        
        # Make sure that no duplicate IDs exist, and that the template exists as well.
        ids = set()
        for graph in c['graphs']:
            graph.setdefault('config', {})
            graph['config'].setdefault('periods', [])
            assert graph['id'] not in ids
            ids.add(graph['id'])
            assert(template_exists(graph['template']))
            
    def create_databases(self, overwrite = False):
        """ A convenience function to create all rrd databases. """
        self.validate_config()
        self.template_runner.create_databases(overwrite)
        
    def start_threadpool(self, pool):
        """ Schedules the start of a threadpool, and schedule the stop of it when the reactor shuts down. """
        if not pool.started:
            reactor.callWhenRunning(self._really_start_threadpool, pool)
            
    def _really_start_threadpool(self, pool):
        """ Starts the threadpool with out scheduleing it via the reactor. """
        if pool.started:
            return
        pool.start()
        reactor.addSystemEventTrigger('after', 'shutdown', pool.stop)
        log.msg('Started threadpool [%s, min=%i, max=%i]' % (pool.name, pool.min, pool.max), logLevel = logging.INFO)
        
    def run(self, **config_args):
        """
            Run the stats application, example below:
            
            >>> from stats import Stats
            >>> s = Stats(__name__)
            >>> s.config.load('config.py')
            >>> s.create_databases()
            >>> s.run()

        """
        # Load and validate the configuration.
        self.config.update(config_args)
        self.validate_config()
        
        # Schedule the start of the threadpools.
        self.wsgi_threadpool.adjustPoolsize(minthreads = self.config['wsgi_min_threads'], maxthreads=self.config['wsgi_max_threads'])
        self.start_threadpool(self.wsgi_threadpool)
        
        # Start the web server and the template runner.
        self.template_runner.run()
        self.flask_app.run()
        
        # Finally, start the twisted reactor.
        reactor.run()
开发者ID:e000,项目名称:prickle,代码行数:101,代码来源:stats.py


注:本文中的twisted.python.threadpool.ThreadPool.adjustPoolsize方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。