Skip to content

Commit

Permalink
Add -X, --maxtasksperchild argument to allow limiting how many suites…
Browse files Browse the repository at this point in the history
… a process runs before quitting (default is never quitting)
  • Loading branch information
CleanCut committed Jul 15, 2021
1 parent 69f4005 commit 4770654
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
7 changes: 7 additions & 0 deletions cli-options.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@ Concurrency Options:
Same as --initializer, only run at the end of a worker
process's lifetime. Used to unprovision resources
provisioned by the initializer.
-X NUM, --maxtasksperchild NUM
Passed directly as the `maxtasksperchild` argument to
an internal `multiprocessing.pool.Pool`. A "task" in
this context usually corresponds to a test suite
consisting of all the tests in a single file. This
option slows down testing, but has the benefit of
guaranteeing a new Python process for each test suite.

Format Options:
-t, --termcolor Force terminal colors on. Default is to autodetect.
Expand Down
23 changes: 22 additions & 1 deletion green/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
processes=multiprocessing.cpu_count(),
initializer="",
finalizer="",
maxtasksperchild=None,
termcolor=None,
notermcolor=None,
disable_windows=False,
Expand Down Expand Up @@ -208,6 +209,20 @@ def parseArguments(argv=None): # pragma: no cover
default=argparse.SUPPRESS,
)
)
store_opt(
concurrency_args.add_argument(
"-X",
"--maxtasksperchild",
action="store",
metavar="NUM",
type=int,
help="Passed directly as the `maxtasksperchild` argument to an internal "
'`multiprocessing.pool.Pool`. A "task" in this context usually corresponds to a test '
"suite consisting of all the tests in a single file. This option slows down testing, "
"but has the benefit of guaranteeing a new Python process for each test suite.",
default=argparse.SUPPRESS,
)
)

format_args = parser.add_argument_group("Format Options")
store_opt(
Expand Down Expand Up @@ -686,7 +701,13 @@ def mergeConfig(args, testing=False): # pragma: no cover
"quiet_coverage",
]:
config_getter = config.getboolean
elif name in ["processes", "debug", "verbose", "minimum_coverage"]:
elif name in [
"processes",
"debug",
"verbose",
"minimum_coverage",
"maxtasksperchild",
]:
config_getter = config.getint
elif name in [
"file_pattern",
Expand Down
1 change: 1 addition & 0 deletions green/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ def run(suite, stream, args, testing=False):
processes=args.processes or None,
initializer=InitializerOrFinalizer(args.initializer),
finalizer=InitializerOrFinalizer(args.finalizer),
maxtasksperchild=args.maxtasksperchild,
)
manager = multiprocessing.Manager()
targets = [(target, manager.Queue()) for target in parallel_targets]
Expand Down

0 comments on commit 4770654

Please sign in to comment.