Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def _time_iteration(self, generator, func_name):
while True:
timer = stats.timer()
try:
tile = next(generator)
except StopIteration:
break
except RuntimeError as e:
if isinstance(e.__cause__, StopIteration):
# since python 3.7, a StopIteration is wrapped in a RuntimeError (PEP 479)
break
else:
raise
timer.stop(self._get_stats_name(func_name, tile))
yield tile
def callback(tile):
if tile:
if hasattr(tile, self.attr):
timer = getattr(tile, self.attr)
delta_t = timer.stop()
if statistics:
statistics.add(delta_t)
else:
setattr(tile, self.attr, stats.timer([key]))
return tile