mirror of
https://chromium.googlesource.com/chromium/tools/depot_tools.git
synced 2026-01-11 18:51:29 +00:00
Caffeinate fetches on Mac.
Since fetches involve multiple subprocess calls, any of which can be slow, the per-subprocess caffeination strategy does not seem suitable -- the Mac might sleep as soon as the wake lock is dropped, before it starts a new one. This instead implements a context manager to allow caffeinating a scope. To allow flag control, caffeinate.scope takes an argument that decides whether or not it should actually do anything useful; it looks silly, but the alternative is to interfere with flag parsing more or to require users to write separate codepaths to decide whether to enter the context manager scope or not; the "use the context manager in a mode where it does not do anything" prevents this. Bug: 462507017 Change-Id: Icc5bb9cadda30b5a120f112b10bf96ffd3b6550f Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/7183647 Reviewed-by: Gavin Mak <gavinmak@google.com> Commit-Queue: Adam Norberg <norberg@google.com>
This commit is contained in:
13
fetch.py
13
fetch.py
@@ -24,6 +24,7 @@ import shlex
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
import caffeinate
|
||||
import gclient_utils
|
||||
import git_common
|
||||
|
||||
@@ -215,6 +216,13 @@ def handle_args(argv):
|
||||
type=str,
|
||||
default=None,
|
||||
help='Protocol to use to fetch dependencies, defaults to https.')
|
||||
parser.add_argument(
|
||||
'--caffeinate',
|
||||
action=argparse.BooleanOptionalAction,
|
||||
default=True,
|
||||
help=('On macOS, prevent idle sleep during the operation. Enabled by'
|
||||
' default. Use --no-caffeinate to disable. No effect on other'
|
||||
' platforms.'))
|
||||
|
||||
parser.add_argument('config',
|
||||
type=str,
|
||||
@@ -306,8 +314,9 @@ def run(options, spec, root):
|
||||
|
||||
def main():
|
||||
args = handle_args(sys.argv)
|
||||
spec, root = run_config_fetch(args.config, args.props)
|
||||
return run(args, spec, root)
|
||||
with caffeinate.scope(actually_caffeinate=args.caffeinate):
|
||||
spec, root = run_config_fetch(args.config, args.props)
|
||||
return run(args, spec, root)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
Reference in New Issue
Block a user