Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(289)

Side by Side Diff: git_cache.py

Issue 1785083005: Set default --lock_timeout to 5m (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/depot_tools
Patch Set: updated comment Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « gclient.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright 2014 The Chromium Authors. All rights reserved. 2 # Copyright 2014 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 """A git command for managing a local cache of git repositories.""" 6 """A git command for managing a local cache of git repositories."""
7 7
8 from __future__ import print_function 8 from __future__ import print_function
9 import errno 9 import errno
10 import logging 10 import logging
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 return 86 return
87 time.sleep(3) 87 time.sleep(3)
88 raise LockError('Failed to remove lock: %s' % lockfile) 88 raise LockError('Failed to remove lock: %s' % lockfile)
89 else: 89 else:
90 os.remove(self.lockfile) 90 os.remove(self.lockfile)
91 91
92 def lock(self): 92 def lock(self):
93 """Acquire the lock. 93 """Acquire the lock.
94 94
95 This will block with a deadline of self.timeout seconds. 95 This will block with a deadline of self.timeout seconds.
96 If self.timeout is zero, this is a NON-BLOCKING FAIL-FAST operation.
97 """ 96 """
98 elapsed = 0 97 elapsed = 0
99 while True: 98 while True:
100 try: 99 try:
101 self._make_lockfile() 100 self._make_lockfile()
102 return 101 return
103 except OSError as e: 102 except OSError as e:
104 if elapsed < self.timeout: 103 if elapsed < self.timeout:
105 sleep_time = min(3, self.timeout - elapsed) 104 sleep_time = max(10, min(3, self.timeout - elapsed))
106 logging.info('Could not create git cache lockfile; ' 105 logging.info('Could not create git cache lockfile; '
107 'will retry after sleep(%d).', sleep_time); 106 'will retry after sleep(%d).', sleep_time);
108 elapsed += sleep_time 107 elapsed += sleep_time
109 time.sleep(sleep_time) 108 time.sleep(sleep_time)
110 continue 109 continue
111 if e.errno == errno.EEXIST: 110 if e.errno == errno.EEXIST:
112 raise LockError("%s is already locked" % self.path) 111 raise LockError("%s is already locked" % self.path)
113 else: 112 else:
114 raise LockError("Failed to create %s (err %s)" % (self.path, e.errno)) 113 raise LockError("Failed to create %s (err %s)" % (self.path, e.errno))
115 114
(...skipping 610 matching lines...) Expand 10 before | Expand all | Expand 10 after
726 dispatcher = subcommand.CommandDispatcher(__name__) 725 dispatcher = subcommand.CommandDispatcher(__name__)
727 return dispatcher.execute(OptionParser(), argv) 726 return dispatcher.execute(OptionParser(), argv)
728 727
729 728
730 if __name__ == '__main__': 729 if __name__ == '__main__':
731 try: 730 try:
732 sys.exit(main(sys.argv[1:])) 731 sys.exit(main(sys.argv[1:]))
733 except KeyboardInterrupt: 732 except KeyboardInterrupt:
734 sys.stderr.write('interrupted\n') 733 sys.stderr.write('interrupted\n')
735 sys.exit(1) 734 sys.exit(1)
OLDNEW
« no previous file with comments | « gclient.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698