本文整理汇总了Python中twisted.internet.reactor.suggestThreadPoolSize方法的典型用法代码示例。如果您正苦于以下问题:Python reactor.suggestThreadPoolSize方法的具体用法?Python reactor.suggestThreadPoolSize怎么用?Python reactor.suggestThreadPoolSize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类twisted.internet.reactor
的用法示例。
在下文中一共展示了reactor.suggestThreadPoolSize方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from twisted.internet import reactor [as 别名]
# 或者: from twisted.internet.reactor import suggestThreadPoolSize [as 别名]
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)
示例2: main
# 需要导入模块: from twisted.internet import reactor [as 别名]
# 或者: from twisted.internet.reactor import suggestThreadPoolSize [as 别名]
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))
示例3: __init__
# 需要导入模块: from twisted.internet import reactor [as 别名]
# 或者: from twisted.internet.reactor import suggestThreadPoolSize [as 别名]
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)
示例4: main
# 需要导入模块: from twisted.internet import reactor [as 别名]
# 或者: from twisted.internet.reactor import suggestThreadPoolSize [as 别名]
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()
示例5: test_suggestThreadPoolSize
# 需要导入模块: from twisted.internet import reactor [as 别名]
# 或者: from twisted.internet.reactor import suggestThreadPoolSize [as 别名]
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)
示例6: setUp
# 需要导入模块: from twisted.internet import reactor [as 别名]
# 或者: from twisted.internet.reactor import suggestThreadPoolSize [as 别名]
def setUp(self):
reactor.suggestThreadPoolSize(8)
示例7: tearDown
# 需要导入模块: from twisted.internet import reactor [as 别名]
# 或者: from twisted.internet.reactor import suggestThreadPoolSize [as 别名]
def tearDown(self):
reactor.suggestThreadPoolSize(0)
示例8: run
# 需要导入模块: from twisted.internet import reactor [as 别名]
# 或者: from twisted.internet.reactor import suggestThreadPoolSize [as 别名]
def run(self):
"""Start the services and run the reactor"""
reactor.suggestThreadPoolSize(constants.THREAD_POOL_SIZE)
self.startService()
reactor.run()
示例9: start_loop
# 需要导入模块: from twisted.internet import reactor [as 别名]
# 或者: from twisted.internet.reactor import suggestThreadPoolSize [as 别名]
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()
示例10: test_suggestThreadPoolSize
# 需要导入模块: from twisted.internet import reactor [as 别名]
# 或者: from twisted.internet.reactor import suggestThreadPoolSize [as 别名]
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)
示例11: do_cleanThreads
# 需要导入模块: from twisted.internet import reactor [as 别名]
# 或者: from twisted.internet.reactor import suggestThreadPoolSize [as 别名]
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()
示例12: testSuggestThreadPoolSize
# 需要导入模块: from twisted.internet import reactor [as 别名]
# 或者: from twisted.internet.reactor import suggestThreadPoolSize [as 别名]
def testSuggestThreadPoolSize(self):
# XXX Uh, how about some asserts?
reactor.suggestThreadPoolSize(34)
reactor.suggestThreadPoolSize(4)
示例13: start_reactor
# 需要导入模块: from twisted.internet import reactor [as 别名]
# 或者: from twisted.internet.reactor import suggestThreadPoolSize [as 别名]
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()
示例14: prepare_twisted_service
# 需要导入模块: from twisted.internet import reactor [as 别名]
# 或者: from twisted.internet.reactor import suggestThreadPoolSize [as 别名]
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()