Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #89841
| Subject | Re: Messages with a time stamp |
|---|---|
| From | Michiel Overtoom <motoom@xs4all.nl> |
| Date | 2015-05-03 11:10 +0200 |
| References | <87r3qykr39.fsf@Equus.decebal.nl> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.56.1430644308.12865.python-list@python.org> (permalink) |
On May 3, 2015, at 10:22, Cecil Westerhof wrote:
> For testing I want my messages time stamped like:
For progress reporting, I often use the module below (eta.py), which also gives a projected time of completion:
import datetime, time, sys
etastart = 0
def eta(done, total, s, reportinterval=100, datetimeformat="%d %b %H:%M:%S"):
global etastart
if done == 0:
etastart = datetime.datetime.now()
if not done % reportinterval:
noww = datetime.datetime.now()
prtnow = noww.strftime(datetimeformat)
if done:
if not isinstance(etastart, datetime.datetime): raise RuntimeError("You should call eta() at least once with done=0")
elapsed = noww - etastart
secsperitem = float(elapsed.seconds) / done
totalsecs = secsperitem * total
eta = etastart + datetime.timedelta(0, totalsecs)
prteta = eta.strftime(datetimeformat)
msg = "now %s, eta %s (%d/%d) %s" % (prtnow, prteta, done, total, s)
else:
msg = "now %s (%d/%d) %s" % (prtnow, done, total, s)
sys.stderr.write(msg + "\n")
if __name__ == "__main__":
for i in range(10):
eta(i, 10, "idling for ten seconds", 1, "%H:%M:%S")
time.sleep(1)
--
"You can't actually make computers run faster, you can only make them do less." - RiderOfGiraffes
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Messages with a time stamp Cecil Westerhof <Cecil@decebal.nl> - 2015-05-03 10:22 +0200
Re: Messages with a time stamp Michiel Overtoom <motoom@xs4all.nl> - 2015-05-03 11:10 +0200
Re: Messages with a time stamp Mark Lawrence <breamoreboy@yahoo.co.uk> - 2015-05-03 10:36 +0100
Re: Messages with a time stamp Cecil Westerhof <Cecil@decebal.nl> - 2015-05-03 12:08 +0200
csiph-web