本文整理汇总了Python中twisted.python.threadpool.ThreadPool.threadFactory方法的典型用法代码示例。如果您正苦于以下问题:Python ThreadPool.threadFactory方法的具体用法?Python ThreadPool.threadFactory怎么用?Python ThreadPool.threadFactory使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类twisted.python.threadpool.ThreadPool
的用法示例。
在下文中一共展示了ThreadPool.threadFactory方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: setup_reactor
# 需要导入模块: from twisted.python.threadpool import ThreadPool [as 别名]
# 或者: from twisted.python.threadpool.ThreadPool import threadFactory [as 别名]
def setup_reactor(self):
"""Setup the Twisted reactor with required customisations."""
def make_daemon_thread(*args, **kw):
"""Create a daemon thread."""
thread = Thread(*args, **kw)
thread.daemon = True
return thread
threadpool = ThreadPool(minthreads=1)
threadpool.threadFactory = make_daemon_thread
reactor.threadpool = threadpool
reactor.callWhenRunning(threadpool.start)
if self.options.max_timeout is not None:
def terminator():
# Hasta la vista, twisted
reactor.stop()
print('Maximum timeout reached: {}s'.format(
self.options.max_timeout))
reactor.callLater(self.options.max_timeout, terminator)
示例2: main
# 需要导入模块: from twisted.python.threadpool import ThreadPool [as 别名]
# 或者: from twisted.python.threadpool.ThreadPool import threadFactory [as 别名]
def main(*args):
"""Parse arguments, then build and run checks in a reactor."""
# We do this first because ArgumentParser won't let us mix and match
# non-default positional argument with a flag argument
if '--version' in sys.argv:
sys.stdout.write('conn-check {}\n'.format(get_version_string()))
return 0
parser = NagiosCompatibleArgsParser()
parser.add_argument("config_file",
help="Config file specifying the checks to run.")
parser.add_argument("patterns", nargs='*',
help="Patterns to filter the checks.")
parser.add_argument("-v", "--verbose", dest="verbose",
action="store_true", default=False,
help="Show additional status")
parser.add_argument("-d", "--duration", dest="show_duration",
action="store_true", default=False,
help="Show duration")
parser.add_argument("-t", "--tracebacks", dest="show_tracebacks",
action="store_true", default=False,
help="Show tracebacks on failure")
parser.add_argument("--validate", dest="validate",
action="store_true", default=False,
help="Only validate the config file, don't run checks.")
parser.add_argument("--version", dest="print_version",
action="store_true", default=False,
help="Print the currently installed version.")
parser.add_argument("--tls-certs-path", dest="cacerts_path",
action="store", default="/etc/ssl/certs/",
help="Path to TLS CA certificates.")
parser.add_argument("--max-timeout", dest="max_timeout", type=float,
action="store", help="Maximum execution time.")
parser.add_argument("--connect-timeout", dest="connect_timeout",
action="store", default=10, type=float,
help="Network connection timeout.")
parser.add_argument("-U", "--unbuffered-output", dest="buffer_output",
action="store_false", default=True,
help="Don't buffer output, write to STDOUT right "
"away.")
group = parser.add_mutually_exclusive_group()
group.add_argument("--include-tags", dest="include_tags",
action="store", default="",
help="Comma separated list of tags to include.")
group.add_argument("--exclude-tags", dest="exclude_tags",
action="store", default="",
help="Comma separated list of tags to exclude.")
options = parser.parse_args(list(args))
load_tls_certs(options.cacerts_path)
if options.patterns:
pattern = SumPattern(map(SimplePattern, options.patterns))
else:
pattern = SimplePattern("*")
def make_daemon_thread(*args, **kw):
"""Create a daemon thread."""
thread = Thread(*args, **kw)
thread.daemon = True
return thread
threadpool = ThreadPool(minthreads=1)
threadpool.threadFactory = make_daemon_thread
reactor.threadpool = threadpool
reactor.callWhenRunning(threadpool.start)
output = sys.stdout
if options.show_duration:
output = TimestampOutput(output)
if options.buffer_output:
# We buffer output so we can order it for human readable output
output = OrderedOutput(output)
include = options.include_tags.split(',') if options.include_tags else []
exclude = options.exclude_tags.split(',') if options.exclude_tags else []
results = ConsoleOutput(output=output,
show_tracebacks=options.show_tracebacks,
show_duration=options.show_duration,
verbose=options.verbose)
results = FailureCountingResultWrapper(results)
with open(options.config_file) as f:
descriptions = yaml.load(f)
checks = build_checks(descriptions, options.connect_timeout, include, exclude)
if options.max_timeout is not None:
def terminator():
# Hasta la vista, twisted
reactor.stop()
print('Maximum timeout reached: {}s'.format(options.max_timeout))
reactor.callLater(options.max_timeout, terminator)
if not options.validate:
reactor.callWhenRunning(run_checks, checks, pattern, results)
#.........这里部分代码省略.........