本文整理汇总了Python中twisted.internet.reactor.suggestThreadPoolSize函数的典型用法代码示例。如果您正苦于以下问题:Python suggestThreadPoolSize函数的具体用法?Python suggestThreadPoolSize怎么用?Python suggestThreadPoolSize使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了suggestThreadPoolSize函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: start_search_tasks
def start_search_tasks():
"""
Before everything, kill if there is any running search tasks. Then start the search tasks
concurrently.
"""
global SEARCH_TASKS
logging.info("(Re)populated config collections from config file. "
"Cancelling previous loops and restarting them again with the new config.")
for looping_task in SEARCH_TASKS:
logging.info("Cancelling this loop: %r", looping_task)
looping_task.stop()
SEARCH_TASKS = []
searches = CONFIG['Searches'].values()
search_count = len(searches)
logging.info("Search count: %d", search_count)
reactor.suggestThreadPoolSize(search_count)
try:
for search in searches:
search_obj = Search(SERVICE_CLASS_MAPPER.get(search['destination']['service']), search,
CONFIG)
do_search_concurrently(search_obj)
except Exception as exception:
logging.exception("Exception occurred while processing search. %s", exception.message)
示例2: startup
def startup():
if not os.path.exists('data/firmware'):
os.makedirs('data/firmware')
if not os.path.exists('data/static'):
os.makedirs('data/static')
if not os.path.exists('data/cert'):
os.makedirs('data/cert')
# Check the certificate file
host = getHost()
validateCertHost('data/cert/key.pem', 'data/cert/cert.pem', 'data/static/thumb.txt', host)
# Start up the HTTPS server
web_port = 443
root_handler = File('./data/static/')
firmware_handler = FirmwareHandler('data/firmware/')
root_handler.putChild('firmware', firmware_handler)
site = Site(root_handler)
site.protocol = MyHttpChannel
reactor.listenTCP(web_port, site)
# Start up the HTTP server
root_handler_http = File("./data/static/")
config_handler = File("./config.html")
root_handler_http.putChild('config.html', config_handler)
site_http = Site(root_handler_http)
reactor.listenTCP(8080, site_http)
reactor.suggestThreadPoolSize(50)
printStatus("Startup complete, running main loop...")
# Run the main loop, this never returns:
reactor.run()
示例3: handle
def handle(self, *args, **options):
try:
dtx_logger_configure(**options)
node_name = options.get('node_name')
node_opts = options.get('node_opts')
thread_pool_size = options.get('thread_pool_size')
if (thread_pool_size):
reactor.suggestThreadPoolSize(thread_pool_size)
log.msg(u'Loading {}'.format(node_name))
node = import_module(node_name)
opts = dict(chain.from_iterable(d.iteritems() for d in [QueryDict(v).dict() for v in node_opts]))
log.msg(u'Starting {} with args {}, kwargs {}'.format(node_name, args, opts))
node.start(*args, **opts)
log.msg(u'Running {}'.format(node_name))
reactor.run()
# TODO: Implement proper shutdown process
for pid, process in started_process_list.items():
log.msg('Stalled subprocess: {}'.format(pid))
process.transport.signalProcess('KILL')
log.msg(u'Finished')
except Exception, exc:
log.err(traceback.format_exc())
raise
示例4: main
def main():
#init logger
logger = logging.getLogger('psp')
hdlr = logging.FileHandler('psp.log')
strm_out = logging.StreamHandler(sys.__stdout__)
formatter = logging.Formatter('%(asctime)s %(levelname)s %(message)s')
hdlr.setFormatter(formatter)
strm_out.setFormatter(formatter)
logger.addHandler(hdlr)
logger.addHandler(strm_out)
logger.setLevel(logging.INFO)
mdns_client = mdns.Mdns_client('laptop', 'haris.sp', 8080, logger)
#init web server
site = server.Site(signpost_server.Singpost_server(logger))
# run method in thread
reactor.suggestThreadPoolSize(30)
factory = Factory()
reactor.listenSSL(8080, site, HTTPSVerifyingContextFactory()) #myContextFactory)
mdns_client.setup_mdns()
#service discovery module
discovery = server_discovery.Server_discovery(logger)
discovery.service_update() #initial discovery to fetch entries
gobject.timeout_add(30000, discovery.service_update)
# run the loop
gobject.threads_init()
gobject.MainLoop().run()
示例5: makeService
def makeService(self, options):
if options['data-dir'] != None:
if not os.access(options['data-dir'], os.X_OK | os.W_OK):
raise core.SmapException("Cannot access " + options['data-dir'])
smapconf.SERVER['DataDir'] = options['data-dir']
inst = loader.load(options['conf'])
# override defaults with command-line args
smapconf.SERVER.update(dict([(k.lower(), v) for (k, v) in
options.iteritems() if v != None]))
if 'SuggestThreadPool' in smapconf.SERVER:
reactor.suggestThreadPoolSize(int(smapconf.SERVER['SuggestThreadPool']))
inst.start()
reactor.addSystemEventTrigger('before', 'shutdown', inst.stop)
site = getSite(inst, docroot=smapconf.SERVER['docroot'])
service = MultiService()
# add HTTP and HTTPS servers to the twisted multiservice
if 'port' in smapconf.SERVER:
service.addService(internet.TCPServer(int(smapconf.SERVER['port']), site))
if 'sslport' in smapconf.SERVER:
service.addService(internet.SSLServer(int(smapconf.SERVER['sslport']),
site,
SslServerContextFactory(smapconf.SERVER)))
return service
示例6: setUp
def setUp(self):
reactor.suggestThreadPoolSize(1)
connection_string = os.environ.get("SHORTENER_TEST_CONNECTION_STRING", "sqlite://")
self.account = "test-account"
cfg = {
"host_domain": "http://wtxt.io",
"account": self.account,
"connection_string": connection_string,
"graphite_endpoint": "tcp:www.example.com:80",
"handlers": [{"dump": "shortener.handlers.dump.Dump"}],
}
self.pool = HTTPConnectionPool(reactor, persistent=False)
self.service = ShortenerServiceApp(reactor=reactor, config=cfg)
self.tr = DisconnectingStringTransport()
endpoint = StringTransportClientEndpoint(reactor, self.tr)
self.service.metrics.carbon_client = CarbonClientService(endpoint)
self.service.metrics.carbon_client.startService()
yield self.service.metrics.carbon_client.connect_d
site = Site(self.service.app.resource())
self.listener = reactor.listenTCP(0, site, interface="localhost")
self.listener_port = self.listener.getHost().port
self._drop_tables()
self.conn = yield self.service.engine.connect()
self.addCleanup(self.listener.loseConnection)
self.addCleanup(self.pool.closeCachedConnections)
示例7: makeService
def makeService(options):
"""
Main entry point into Crossbar.io application. This is called from the Twisted
plugin system to instantiate "crossbar".
"""
## install our log observer before anything else is done
logger = Logger()
twisted.python.log.addObserver(logger)
## import reactor here first and set some thread pool size
from twisted.internet import reactor
reactor.suggestThreadPoolSize(30)
## now actually create our top service and set the logger
service = CrossbarService()
service.logger = logger
## store user options set
service.appdata = options['appdata']
service.webdata = options['webdata']
service.debug = True if options['debug'] else False
service.licenseserver = options['licenseserver']
service.isExe = False # will be set to true iff Crossbar is running from self-contained EXE
return service
示例8: test_make_worker_with_threadpool_size
def test_make_worker_with_threadpool_size(self):
"""
The reactor threadpool can be resized with a command line option.
"""
from twisted.internet import reactor
old_maxthreads = reactor.getThreadPool().max
self.add_cleanup(reactor.suggestThreadPoolSize, old_maxthreads)
# Explicitly set the threadpool size to something different from the
# value we're testing with.
reactor.suggestThreadPoolSize(5)
self.mk_config_file('worker', ["transport_name: sphex"])
maker = VumiWorkerServiceMaker()
# By default, we don't touch the threadpool.
options = StartWorkerOptions()
options.parseOptions([
'--worker-class', 'vumi.demos.words.EchoWorker',
'--config', self.config_file['worker'],
])
worker = maker.makeService(options)
self.assertEqual({'transport_name': 'sphex'}, worker.config)
self.assertEqual(reactor.getThreadPool().max, 5)
# If asked, we set the threadpool's maximum size.
options_mt = StartWorkerOptions()
options_mt.parseOptions([
'--worker-class', 'vumi.demos.words.EchoWorker',
'--config', self.config_file['worker'],
'--maxthreads', '2',
])
worker = maker.makeService(options_mt)
self.assertEqual({'transport_name': 'sphex'}, worker.config)
self.assertEqual(reactor.getThreadPool().max, 2)
示例9: _init
def _init(config, mode='normal'):
from almar.global_config import GlobalConfig, MODE_PROXY, MODE_WORKER
g = GlobalConfig.create_instance(config)
# configure web service
from almar.service import worker_root, proxy_root
from twisted.web import server
if mode == 'proxy':
g.server_mode = MODE_PROXY
if not g.proxy or not g.searcher:
fatal_out('proxy configuration is invalid')
# configure reactor
reactor.suggestThreadPoolSize(int(g.proxy.max_threads))
return int(g.proxy.port), server.Site(proxy_root)
else:
if not g.server or not g.model or not g.database:
fatal_out('server configuration is invalid')
# configure reactor
reactor.suggestThreadPoolSize(int(g.server.max_threads))
g.server_mode = MODE_WORKER
# configure database
from txpostgres import txpostgres
txpostgres.ConnectionPool.min = int(g.database.min_connections)
txpostgres.ConnectionPool.max = int(g.database.max_connections)
from almar.backend.postgresql import PostgreSQLBackend as Backend
Backend.create_instance(g.database)
return int(g.server.port), server.Site(worker_root)
示例10: makeService
def makeService(self, options):
"""
Construct a TCPServer from a factory defined in myproject.
"""
from minitree import configure
c = configure(options["config"])
from twisted.internet import reactor
reactor.suggestThreadPoolSize(int(c.get("server:main", "max_threads")))
from txpostgres import txpostgres
txpostgres.ConnectionPool.min = int(c.get("backend:main",
"max_connections"))
from minitree.db.postgres import dbBackend
dbBackend.connect(c.get("backend:main", "dsn"))
from minitree.service import site_configure
site_root = site_configure(c)
from twisted.web import server
site = server.Site(site_root)
if "socket" in options and options["socket"]:
return internet.UNIXServer(options["socket"], site)
else:
return internet.TCPServer(int(options["port"] or
c.get("server:main", "port")), site)
示例11: do_cleanThreads
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
示例12: suggestThreadpoolSize
def suggestThreadpoolSize(maxThreads):
"""Updates the size of the twisted threadpool
The function must be passed a parameter specifying the maximum number of
generation threads the user has requested.
"""
reactor.suggestThreadPoolSize(int(maxThreads*1.5))
示例13: run_server
def run_server():
# Set logging
stream = None
if logfile:
logging.basicConfig(filename=logfile, level=logging.DEBUG)
elif not daemonized:
logging.basicConfig(filename="/dev/stdout", level=logging.DEBUG)
else:
# If no logging file was given, and we're daemonized, create a temp
# logfile for monitoring.
stream = NamedTemporaryFile(delete=True, suffix=socket2.replace("/", "-"))
logging.basicConfig(stream=stream, level=logging.DEBUG)
logging.info("Socket server started at %s" % socket2)
# Thread sensitive interface for stdout/stdin
std.setup()
# Set thread pool size (max parrallel interactive processes.)
if thread_pool_size:
reactor.suggestThreadPoolSize(thread_pool_size)
# Set process name
set_title(stream.name if stream else logfile)
# Run Twisted reactor
reactor.run()
# Remove logging file (this will automatically delete the NamedTemporaryFile)
if stream:
stream.close()
示例14: startNZBLeecher
def startNZBLeecher():
""" gogogo """
defaultAntiIdle = int(4.5 * 60) # 4.5 minutes
defaultIdleTimeout = 30
totalCount = 0
# Order the initialization of servers by the fillserver priority, if fillserver
# support is enabled
serverDictsByPriority = Hellanzb.SERVERS.items()
if isinstance(Hellanzb.queue, FillServerQueue):
serverDictsByPriority.sort(lambda x, y: cmp(x[1].get('fillserver'),
y[1].get('fillserver')))
for serverId, serverDict in serverDictsByPriority:
if not serverDict.get('enabled') is False:
totalCount += connectServer(serverId, serverDict, defaultAntiIdle, defaultIdleTimeout)
# How large the scroll ticker should be
Hellanzb.scroller.maxCount = totalCount
# Initialize the retry queue, (this only initializes it when it's necessary) for
# automatic failover. It contains multiple sub-queues that work within the NZBQueue,
# for queueing segments that failed to download on particular serverPools.
Hellanzb.queue.initRetryQueue()
# Allocate only one thread, just for decoding
reactor.suggestThreadPoolSize(1)
# Well, there's egg and bacon; egg sausage and bacon; egg and spam; egg bacon and
# spam; egg bacon sausage and spam; spam bacon sausage and spam; spam egg spam spam
# bacon and spam; spam sausage spam spam bacon spam tomato and spam;
reactor.run()
# Spam! Spam! Spam! Spam! Lovely spam! Spam! Spam!
# Safely tear down the app only after the reactor shutdown
finishShutdown()
示例15: main
def main():
args, parser = _parse_args(sys.argv[1:])
end = EndpointHandler
# Add the log attribute
setattr(end, 'log', log)
setattr(args, 'log', log)
annoy = Annoy(args)
log.startLogging(sys.stdout)
# Add the storage
end.ap_settings = args
site = cyclone.web.Application([
(r"/(.*)", end),
],
default_host=args.host,
debug=args.debug,
)
log.msg("Starting on %s" % args.port)
reactor.listenTCP(args.port, site)
reactor.suggestThreadPoolSize(50)
reactor.callLater(args.period, annoy.bother)
reactor.run()