import logging logging.basicConfig(level=logging.INFO) def time_to_log(data, percent=10): percent = percent if percent > 1 else percent * 100 data_size = len(data) log_every = data_size * percent / 100 return float(data_size), lambda i: not i % log_every data = range(100) data_size, is_time_to_log = time_to_log(data, 0.2) for i, d in enumerate(data): if is_time_to_log(i): logging.info("processing... {:.2%}".format(i / data_size)) pass # do whatever is needed logging.info("processing... 100.00%")
here I will gather some notes on my python use. I will give my impressions on different libs when I can give them a try to solve the problem at hand. Also I will announce some releases when I think some of my packages might be useful to others.
Search This Blog
12 October 2015
Output a log message every x% of a long computation
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment