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


Python threadpool.ThreadPool方法代码示例

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


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

示例1: test_wsgi

# 需要导入模块: from twisted.python import threadpool [as 别名]
# 或者: from twisted.python.threadpool import ThreadPool [as 别名]
def test_wsgi(self):
        """
        The I{--wsgi} option takes the fully-qualifed Python name of a WSGI
        application object and creates a L{WSGIResource} at the root which
        serves that application.
        """
        options = Options()
        options.parseOptions(['--wsgi', __name__ + '.application'])
        root = options['root']
        self.assertTrue(root, WSGIResource)
        self.assertIdentical(root._reactor, reactor)
        self.assertTrue(isinstance(root._threadpool, ThreadPool))
        self.assertIdentical(root._application, application)

        # The threadpool should start and stop with the reactor.
        self.assertFalse(root._threadpool.started)
        reactor.fireSystemEvent('startup')
        self.assertTrue(root._threadpool.started)
        self.assertFalse(root._threadpool.joined)
        reactor.fireSystemEvent('shutdown')
        self.assertTrue(root._threadpool.joined) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:23,代码来源:test_tap.py

示例2: test_callInThreadException

# 需要导入模块: from twisted.python import threadpool [as 别名]
# 或者: from twisted.python.threadpool import ThreadPool [as 别名]
def test_callInThreadException(self):
        """
        L{ThreadPool.callInThread} logs exceptions raised by the callable it
        is passed.
        """
        class NewError(Exception):
            pass

        def raiseError():
            raise NewError()

        tp = threadpool.ThreadPool(0, 1)
        tp.callInThread(raiseError)
        tp.start()
        tp.stop()

        errors = self.flushLoggedErrors(NewError)
        self.assertEqual(len(errors), 1) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:20,代码来源:test_threadpool.py

示例3: test_existingWork

# 需要导入模块: from twisted.python import threadpool [as 别名]
# 或者: from twisted.python.threadpool import ThreadPool [as 别名]
def test_existingWork(self):
        """
        Work added to the threadpool before its start should be executed once
        the threadpool is started: this is ensured by trying to release a lock
        previously acquired.
        """
        waiter = threading.Lock()
        waiter.acquire()

        tp = threadpool.ThreadPool(0, 1)
        tp.callInThread(waiter.release) # before start()
        tp.start()

        try:
            self._waitForLock(waiter)
        finally:
            tp.stop() 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:19,代码来源:test_threadpool.py

示例4: __init__

# 需要导入模块: from twisted.python import threadpool [as 别名]
# 或者: from twisted.python.threadpool import ThreadPool [as 别名]
def __init__(self, testCase, *args, **kwargs):
        """
        Create a L{PoolHelper}.

        @param testCase: a test case attached to this helper.

        @type args: The arguments passed to a L{threadpool.ThreadPool}.

        @type kwargs: The arguments passed to a L{threadpool.ThreadPool}
        """
        coordinator, self.performCoordination = createMemoryWorker()
        self.workers = []
        def newWorker():
            self.workers.append(createMemoryWorker())
            return self.workers[-1][0]
        self.threadpool = MemoryPool(coordinator, testCase.fail, newWorker,
                                     *args, **kwargs) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:19,代码来源:test_threadpool.py

示例5: test_integration

# 需要导入模块: from twisted.python import threadpool [as 别名]
# 或者: from twisted.python.threadpool import ThreadPool [as 别名]
def test_integration(self, logger):
        """
        ``auto_threaded`` works with ``twisted.python.threads.ThreadPool``.
        """
        from twisted.internet import reactor

        threadpool = ThreadPool(minthreads=1, name=self.id())
        threadpool.start()
        self.addCleanup(threadpool.stop)

        spy = Spy()
        async_spy = AsyncSpy(
            reactor=reactor, threadpool=threadpool, provider=spy
        )

        a = [object()]
        b = [object()]
        c = [object()]
        with LOG_IN_CALLER():
            result = async_spy.method(a, b, c)
        result.addCallback(self.assertEqual, spy.method(a, b, c))
        return result 
开发者ID:ClusterHQ,项目名称:flocker,代码行数:24,代码来源:test_thread.py

示例6: test_existingWork

# 需要导入模块: from twisted.python import threadpool [as 别名]
# 或者: from twisted.python.threadpool import ThreadPool [as 别名]
def test_existingWork(self):
        """
        Work added to the threadpool before its start should be executed once
        the threadpool is started: this is ensured by trying to release a lock
        previously acquired.
        """
        waiter = threading.Lock()
        waiter.acquire()

        tp = threadpool.ThreadPool(0, 1)
        tp.callInThread(waiter.release)  # Before start()
        tp.start()

        try:
            self._waitForLock(waiter)
        finally:
            tp.stop() 
开发者ID:wistbean,项目名称:learn_python3_spider,代码行数:19,代码来源:test_threadpool.py

示例7: __init__

# 需要导入模块: from twisted.python import threadpool [as 别名]
# 或者: from twisted.python.threadpool import ThreadPool [as 别名]
def __init__(self, testCase, *args, **kwargs):
        """
        Create a L{PoolHelper}.

        @param testCase: a test case attached to this helper.

        @type args: The arguments passed to a L{threadpool.ThreadPool}.

        @type kwargs: The arguments passed to a L{threadpool.ThreadPool}
        """
        coordinator, self.performCoordination = createMemoryWorker()
        self.workers = []

        def newWorker():
            self.workers.append(createMemoryWorker())
            return self.workers[-1][0]

        self.threadpool = MemoryPool(coordinator, testCase.fail, newWorker,
                                     *args, **kwargs) 
开发者ID:wistbean,项目名称:learn_python3_spider,代码行数:21,代码来源:test_threadpool.py

示例8: run

# 需要导入模块: from twisted.python import threadpool [as 别名]
# 或者: from twisted.python.threadpool import ThreadPool [as 别名]
def run(self, handler):
        from twisted.web import server, wsgi
        from twisted.python.threadpool import ThreadPool
        from twisted.internet import reactor
        thread_pool = ThreadPool()
        thread_pool.start()
        reactor.addSystemEventTrigger('after', 'shutdown', thread_pool.stop)
        factory = server.Site(wsgi.WSGIResource(reactor, thread_pool, handler))
        reactor.listenTCP(self.port, factory, interface=self.host)
        reactor.run() 
开发者ID:Autodesk,项目名称:arnold-usd,代码行数:12,代码来源:__init__.py

示例9: setupService

# 需要导入模块: from twisted.python import threadpool [as 别名]
# 或者: from twisted.python.threadpool import ThreadPool [as 别名]
def setupService(self):

        self.log(log.info, u'Bootstrapping')
        self.settings = self.parent.settings

        # Optionally register subsystem component as child service
        for subsystem in self.subsystems:
            if hasattr(self, subsystem):
                subsystem_service = getattr(self, subsystem)
                if isinstance(subsystem_service, Service):
                    log.info('Registering subsystem component "{subsystem}" as service', subsystem=subsystem)
                    self.registerService(subsystem_service)

        # Configure metrics to be collected each X seconds
        metrics_interval = int(self.channel.get('metrics_logger_interval', 60))
        self.metrics = Bunch(tx_count=0, starttime=time.time(), interval=metrics_interval)

        subscriptions = read_list(self.channel.mqtt_topics)
        self.mqtt_service = MqttAdapter(
            name          = u'mqtt-' + self.channel.realm,
            broker_host   = self.settings.mqtt.host,
            broker_port   = int(self.settings.mqtt.port),
            broker_username = self.settings.mqtt.username,
            broker_password = self.settings.mqtt.password,
            callback      = self.mqtt_receive,
            subscriptions = subscriptions)

        self.registerService(self.mqtt_service)

        self.influx = InfluxDBAdapter(settings = self.settings.influxdb)

        # Perform MQTT message processing using a different thread pool
        self.threadpool = ThreadPool()
        self.thimble = Thimble(reactor, self.threadpool, self, ["process_message"]) 
开发者ID:daq-tools,项目名称:kotori,代码行数:36,代码来源:mig.py

示例10: run

# 需要导入模块: from twisted.python import threadpool [as 别名]
# 或者: from twisted.python.threadpool import ThreadPool [as 别名]
def run(self, handler):
        from twisted.web import server, wsgi
        from twisted.python.threadpool import ThreadPool
        from twisted.internet import reactor
        thread_pool = ThreadPool()
        thread_pool.start()
        reactor.addSystemEventTrigger('after', 'shutdown', thread_pool.stop)
        factory = server.Site(wsgi.WSGIResource(reactor, thread_pool, handler))
        reactor.listenTCP(self.port, factory, interface=self.host)
        if not reactor.running:
            reactor.run() 
开发者ID:brycesub,项目名称:silvia-pi,代码行数:13,代码来源:bottle.py

示例11: opt_wsgi

# 需要导入模块: from twisted.python import threadpool [as 别名]
# 或者: from twisted.python.threadpool import ThreadPool [as 别名]
def opt_wsgi(self, name):
        """
        The FQPN of a WSGI application object to serve as the root resource of
        the webserver.
        """
        try:
            application = reflect.namedAny(name)
        except (AttributeError, ValueError):
            raise usage.UsageError("No such WSGI application: %r" % (name,))
        pool = threadpool.ThreadPool()
        reactor.callWhenRunning(pool.start)
        reactor.addSystemEventTrigger('after', 'shutdown', pool.stop)
        self['root'] = wsgi.WSGIResource(reactor, pool, application) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:15,代码来源:tap.py

示例12: enableThreads

# 需要导入模块: from twisted.python import threadpool [as 别名]
# 或者: from twisted.python.threadpool import ThreadPool [as 别名]
def enableThreads(self):
        self.reactor = reactor
        self.threadpool = ThreadPool()
        self.threadpool.start()
        self.addCleanup(self.threadpool.stop) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:7,代码来源:test_wsgi.py

示例13: _initThreadPool

# 需要导入模块: from twisted.python import threadpool [as 别名]
# 或者: from twisted.python.threadpool import ThreadPool [as 别名]
def _initThreadPool(self):
            """
            Create the threadpool accessible with callFromThread.
            """
            from twisted.python import threadpool
            self.threadpool = threadpool.ThreadPool(
                0, 10, 'twisted.internet.reactor')
            self._threadpoolStartupID = self.callWhenRunning(
                self.threadpool.start)
            self.threadpoolShutdownID = self.addSystemEventTrigger(
                'during', 'shutdown', self._stopThreadPool) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:13,代码来源:base.py

示例14: deterministicPool

# 需要导入模块: from twisted.python import threadpool [as 别名]
# 或者: from twisted.python.threadpool import ThreadPool [as 别名]
def deterministicPool():
    """
    Create a deterministic threadpool.

    @return: 2-tuple of L{ThreadPool}, 0-argument C{work} callable; when
        C{work} is called, do the work.
    """
    worker, doer = createMemoryWorker()
    return (
        DeterministicThreadPool(Team(LockWorker(Lock(), local()),
                                     (lambda: worker), lambda: None)),
        doer
    ) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:15,代码来源:test_resolver.py

示例15: test_getThreadPool

# 需要导入模块: from twisted.python import threadpool [as 别名]
# 或者: from twisted.python.threadpool import ThreadPool [as 别名]
def test_getThreadPool(self):
        """
        C{reactor.getThreadPool()} returns an instance of L{ThreadPool} which
        starts when C{reactor.run()} is called and stops before it returns.
        """
        state = []
        reactor = self.buildReactor()

        pool = reactor.getThreadPool()
        self.assertIsInstance(pool, ThreadPool)
        self.assertFalse(
            pool.started, "Pool should not start before reactor.run")

        def f():
            # Record the state for later assertions
            state.append(pool.started)
            state.append(pool.joined)
            reactor.stop()

        reactor.callWhenRunning(f)
        self.runReactor(reactor, 2)

        self.assertTrue(
            state[0], "Pool should start after reactor.run")
        self.assertFalse(
            state[1], "Pool should not be joined before reactor.stop")
        self.assertTrue(
            pool.joined,
            "Pool should be stopped after reactor.run returns") 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:31,代码来源:test_threads.py


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