Python twisted.internet.reactor.suggestThreadPoolSize() Examples

The following are 22 code examples of twisted.internet.reactor.suggestThreadPoolSize(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module twisted.internet.reactor , or try the search function .
Example #1
Source File: forwarder.py    From telepresence with Apache License 2.0 6 votes vote down vote up
def main():
    namespace = _get_env_namespace()
    if namespace is None:
        namespace = _get_sa_namespace()
    if namespace is None:
        namespace = _guess_namespace()
    if namespace is None:
        print("\nERROR: Failed to determine namespace")
        print("Enable serviceaccount access via")
        print("  automountServiceAccountToken: true")
        print("in your Deployment")
        print("or set the TELEPRESENCE_CONTAINER_NAMESPACE env var")
        print("directly or using the Downward API.\n")
        exit("ERROR: Failed to determine namespace")
    print("Pod's namespace is {!r}".format(namespace))
    telepresence_nameserver = os.environ.get("TELEPRESENCE_NAMESERVER")
    reactor.suggestThreadPoolSize(50)
    periodic.setup(reactor)
    print("Listening...")
    listen(resolver.LocalResolver(telepresence_nameserver, namespace)) 
Example #2
Source File: vmware_exporter.py    From vmware_exporter with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def main(argv=None):
    """ start up twisted reactor """
    parser = argparse.ArgumentParser(description='VMWare metrics exporter for Prometheus')
    parser.add_argument('-c', '--config', dest='config_file',
                        default=None, help="configuration file")
    parser.add_argument('-p', '--port', dest='port', type=int,
                        default=9272, help="HTTP port to expose metrics")
    parser.add_argument('-l', '--loglevel', dest='loglevel',
                        default="INFO", help="Set application loglevel INFO, DEBUG")

    args = parser.parse_args(argv or sys.argv[1:])

    numeric_level = getattr(logging, args.loglevel.upper(), None)
    if not isinstance(numeric_level, int):
        raise ValueError("Invalid log level: {level}".format(level=args.loglevel))
    logging.basicConfig(level=numeric_level, format='%(asctime)s %(levelname)s:%(message)s')

    reactor.suggestThreadPoolSize(25)

    factory = Site(registerEndpoints(args))
    logging.info("Starting web server on port {port}".format(port=args.port))
    endpoint = endpoints.TCP4ServerEndpoint(reactor, args.port)
    endpoint.listen(factory)
    reactor.run() 
Example #3
Source File: server.py    From Rasa_NLU_Chi with Apache License 2.0 6 votes vote down vote up
def __init__(self,
                 data_router,
                 loglevel='INFO',
                 logfile=None,
                 num_threads=1,
                 token=None,
                 cors_origins=None,
                 testing=False,
                 default_config_path=None):

        self._configure_logging(loglevel, logfile)

        self.default_model_config = self._load_default_config(
                default_config_path)

        self.data_router = data_router
        self._testing = testing
        self.cors_origins = cors_origins if cors_origins else ["*"]
        self.access_token = token
        reactor.suggestThreadPoolSize(num_threads * 5) 
Example #4
Source File: server.py    From rasa_nlu with Apache License 2.0 6 votes vote down vote up
def __init__(self,
                 data_router,
                 loglevel='INFO',
                 logfile=None,
                 num_threads=1,
                 token=None,
                 cors_origins=None,
                 testing=False,
                 default_config_path=None):

        self._configure_logging(loglevel, logfile)

        self.default_model_config = self._load_default_config(
            default_config_path)

        self.data_router = data_router
        self._testing = testing
        self.cors_origins = cors_origins if cors_origins else ["*"]
        self.access_token = token
        reactor.suggestThreadPoolSize(num_threads * 5) 
Example #5
Source File: server.py    From rasa_nlu with Apache License 2.0 6 votes vote down vote up
def __init__(self,
                 data_router,
                 loglevel='INFO',
                 logfile=None,
                 num_threads=1,
                 token=None,
                 cors_origins=None,
                 testing=False,
                 default_config_path=None):

        self._configure_logging(loglevel, logfile)

        self.default_model_config = self._load_default_config(
            default_config_path)

        self.data_router = data_router
        self._testing = testing
        self.cors_origins = cors_origins if cors_origins else ["*"]
        self.access_token = token
        reactor.suggestThreadPoolSize(num_threads * 5) 
Example #6
Source File: test_threads.py    From python-for-android with Apache License 2.0 5 votes vote down vote up
def setUp(self):
        reactor.suggestThreadPoolSize(8) 
Example #7
Source File: test_threads.py    From Safejumper-for-Desktop with GNU General Public License v2.0 5 votes vote down vote up
def setUp(self):
        reactor.suggestThreadPoolSize(8) 
Example #8
Source File: main.py    From voltha with Apache License 2.0 5 votes vote down vote up
def start_reactor(self):
        reactor.callWhenRunning(
            lambda: self.log.info('twisted-reactor-started'))

        reactor.addSystemEventTrigger('before', 'shutdown',
                                      self.shutdown_components)
        reactor.suggestThreadPoolSize(30)
        reactor.run() 
Example #9
Source File: test_threads.py    From Safejumper-for-Desktop with GNU General Public License v2.0 5 votes vote down vote up
def tearDown(self):
        reactor.suggestThreadPoolSize(0) 
Example #10
Source File: test_threads.py    From BitTorrent with GNU General Public License v3.0 5 votes vote down vote up
def tearDown(self):
        reactor.suggestThreadPoolSize(0) 
Example #11
Source File: test_threads.py    From BitTorrent with GNU General Public License v3.0 5 votes vote down vote up
def setUp(self):
        reactor.suggestThreadPoolSize(8) 
Example #12
Source File: test_threads.py    From BitTorrent with GNU General Public License v3.0 5 votes vote down vote up
def testSuggestThreadPoolSize(self):
        # XXX Uh, how about some asserts?
        reactor.suggestThreadPoolSize(34)
        reactor.suggestThreadPoolSize(4) 
Example #13
Source File: util.py    From BitTorrent with GNU General Public License v3.0 5 votes vote down vote up
def do_cleanThreads(cls):
        from twisted.internet import reactor
        if interfaces.IReactorThreads.providedBy(reactor):
            reactor.suggestThreadPoolSize(0)
            if hasattr(reactor, 'threadpool') and reactor.threadpool:
                reactor.threadpool.stop()
                reactor.threadpool = None
                # *Put it back* and *start it up again*.  The
                # reactor's threadpool is *private*: we cannot just
                # rape it and walk away.
                reactor.threadpool = threadpool.ThreadPool(0, 10)
                reactor.threadpool.start() 
Example #14
Source File: test_threads.py    From python-for-android with Apache License 2.0 5 votes vote down vote up
def tearDown(self):
        reactor.suggestThreadPoolSize(0) 
Example #15
Source File: utility.py    From pade with MIT License 5 votes vote down vote up
def start_loop(agents):
    reactor.suggestThreadPoolSize(30)
    for agent in agents:
        agent.update_ams(agent.ams)
        agent.on_start()
        ILP = reactor.listenTCP(agent.aid.port, agent.agentInstance)
        agent.ILP = ILP
    reactor.run() 
Example #16
Source File: test_threads.py    From python-for-android with Apache License 2.0 5 votes vote down vote up
def test_suggestThreadPoolSize(self):
        """
        Try to change maximum number of threads.
        """
        reactor.suggestThreadPoolSize(34)
        self.assertEquals(reactor.threadpool.max, 34)
        reactor.suggestThreadPoolSize(4)
        self.assertEquals(reactor.threadpool.max, 4) 
Example #17
Source File: test_threads.py    From Safejumper-for-Desktop with GNU General Public License v2.0 5 votes vote down vote up
def test_suggestThreadPoolSize(self):
        """
        Try to change maximum number of threads.
        """
        reactor.suggestThreadPoolSize(34)
        self.assertEqual(reactor.threadpool.max, 34)
        reactor.suggestThreadPoolSize(4)
        self.assertEqual(reactor.threadpool.max, 4) 
Example #18
Source File: main.py    From autopush with Mozilla Public License 2.0 5 votes vote down vote up
def run(self):
        """Start the services and run the reactor"""
        reactor.suggestThreadPoolSize(constants.THREAD_POOL_SIZE)
        self.startService()
        reactor.run() 
Example #19
Source File: test_threads.py    From learn_python3_spider with MIT License 5 votes vote down vote up
def tearDown(self):
        reactor.suggestThreadPoolSize(0) 
Example #20
Source File: test_threads.py    From learn_python3_spider with MIT License 5 votes vote down vote up
def setUp(self):
        reactor.suggestThreadPoolSize(8) 
Example #21
Source File: test_threads.py    From learn_python3_spider with MIT License 5 votes vote down vote up
def test_suggestThreadPoolSize(self):
        """
        Try to change maximum number of threads.
        """
        reactor.suggestThreadPoolSize(34)
        self.assertEqual(reactor.threadpool.max, 34)
        reactor.suggestThreadPoolSize(4)
        self.assertEqual(reactor.threadpool.max, 4) 
Example #22
Source File: __init__.py    From yabgp with Apache License 2.0 4 votes vote down vote up
def prepare_twisted_service(handler, reactor_thread_size=100):
    """prepare twsited service
    """
    LOG.info('Prepare twisted services')

    LOG.info('Get peer configuration')
    for conf_key in CONF.bgp.running_config:
        LOG.info('---%s = %s', conf_key, CONF.bgp.running_config[conf_key])

    # init handler
    handler.init()

    LOG.info('Create BGPPeering twsited instance')
    afi_safi_list = [bgp_cons.AFI_SAFI_STR_DICT[afi_safi] for afi_safi in CONF.bgp.running_config['afi_safi']]
    CONF.bgp.running_config['afi_safi'] = afi_safi_list
    CONF.bgp.running_config['capability']['local']['afi_safi'] = afi_safi_list
    bgp_peering = BGPPeering(
        myasn=CONF.bgp.running_config['local_as'],
        myaddr=CONF.bgp.running_config['local_addr'],
        peerasn=CONF.bgp.running_config['remote_as'],
        peeraddr=CONF.bgp.running_config['remote_addr'],
        afisafi=CONF.bgp.running_config['afi_safi'],
        md5=CONF.bgp.running_config['md5'],
        handler=handler
    )
    CONF.bgp.running_config['factory'] = bgp_peering

    # Starting api server
    LOG.info("Prepare RESTAPI service")
    LOG.info("reactor_thread_size = %s", reactor_thread_size)
    reactor.suggestThreadPoolSize(reactor_thread_size)
    resource = WSGIResource(reactor, reactor.getThreadPool(), app)
    site = Site(resource)
    try:
        reactor.listenTCP(CONF.rest.bind_port, site, interface=CONF.rest.bind_host)
        LOG.info("serving RESTAPI on http://%s:%s", CONF.rest.bind_host, CONF.rest.bind_port)
    except Exception as e:
        LOG.error(e, exc_info=True)
        sys.exit()

    LOG.info('Starting BGPPeering twsited instance')
    bgp_peering.automatic_start()

    reactor.run()