Skip to content

Commit 9081d57

Browse files
committed
Replace some while loops with for loops
1 parent 212d402 commit 9081d57

2 files changed

Lines changed: 3 additions & 9 deletions

File tree

cms/util.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -184,13 +184,11 @@ def get_service_shards(service):
184184
returns (int): the number of shards defined in the configuration.
185185
186186
"""
187-
i = 0
188-
while True:
187+
for i in itertools.count():
189188
try:
190189
get_service_address(ServiceCoord(service, i))
191190
except KeyError:
192191
return i
193-
i += 1
194192

195193

196194
def default_argument_parser(description, cls, ask_contest=None):

cmstestsuite/programstarter.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -204,9 +204,7 @@ def kill(self):
204204
def _check_with_backoff(self):
205205
"""Check and wait that the service is healthy."""
206206
self.healthy = False
207-
attempts = 0
208-
while attempts < _MAX_ATTEMPTS:
209-
attempts += 1
207+
for attempts in range(_MAX_ATTEMPTS):
210208
self._check()
211209
if not self.healthy:
212210
time.sleep(0.2 * (1.2 ** attempts))
@@ -321,9 +319,7 @@ def count_unhealthy(self):
321319
return len([p for p in itervalues(self._programs) if not p.healthy])
322320

323321
def wait(self):
324-
attempts = 0
325-
while attempts <= _MAX_ATTEMPTS:
326-
attempts += 1
322+
for attempts in range(_MAX_ATTEMPTS):
327323
unhealthy = self.count_unhealthy()
328324
if unhealthy == 0:
329325
logger.info("All healthy! Continuing.")

0 commit comments

Comments
 (0)