I play with the Python method datetime.datetime.utcnow (), and I notice that the value of the microsecond is always the same.
>>> import datetime >>> datetime.datetime.utcnow() datetime.datetime(2015, 11, 16, 23, 20, 46, 42286) >>> datetime.datetime.utcnow() datetime.datetime(2015, 11, 16, 23, 20, 55, 505286) >>> datetime.datetime.utcnow() datetime.datetime(2015, 11, 16, 23, 21, 1, 552286)
Note that the microsecond value is always 286. Why? And what can I do to fix this?
A bit more info: time.time() also always has 286us. The values ββin milliseconds are beautiful. I think this is actually the root cause, since I believe datetime.datetime.utcnow () calls time.time ().
Here's a short script that shows that this is not just luck:
import datetime, random, time for wait_time in [random.random() for _ in range(10)]: time.sleep(wait_time) print("Waited {}, result {}".format(wait_time, datetime.datetime.utcnow()))
Result:
Waited 0.6074311218736113, result 2015-11-16 23:35:24.603286 Waited 0.960317012489652, result 2015-11-16 23:35:25.563286 Waited 0.13555474339177553, result 2015-11-16 23:35:25.698286 Waited 0.6179213307667111, result 2015-11-16 23:35:26.315286 Waited 0.2872301475401443, result 2015-11-16 23:35:26.602286 Waited 0.42578113509089066, result 2015-11-16 23:35:27.027286 Waited 0.647233264729425, result 2015-11-16 23:35:27.674286 Waited 0.38930513172405146, result 2015-11-16 23:35:28.063286 Waited 0.6500370260649043, result 2015-11-16 23:35:28.713286 Waited 0.9807308512288959, result 2015-11-16 23:35:29.693286
Thanks,
System Information:
- Python 3.4.3 (v3.4.3: 9b73f1c3e601, February 24, 2015, 22:44:40) [MSC v.1600 64 bit (AMD64)] on win32
- Windows 7 Professional, Service Pack 1. 64-bit.
- Intel Core i5-2400 @ 3.10GHz
Results time.get_clock_info ()
Name Adjustable Implementation Monotonic Resolution (seconds) ============ ========== ========================= ========= ==================== clock False QueryPerformanceCounter() True 3.3106597e-07 monotomic False GetTickCount64() True 0.015600099999 perf_counter False QueryPerformanceCounter() True 3.3106597e-07 process_time False GetProcessTime() True 1e-7 time True GetSystemTimeAsFileTime() False 0.015600099999
Final Edit:
So, I will come back to this the next morning (the computer stayed all night), and I started the python interpreter again, and now everything is fine!
What the hell is a man?
>>> datetime.datetime.utcnow() datetime.datetime(2015, 11, 17, 17, 19, 17, 626982) >>> datetime.datetime.utcnow() datetime.datetime(2015, 11, 17, 17, 19, 18, 234043) >>> datetime.datetime.utcnow() datetime.datetime(2015, 11, 17, 17, 19, 19, 106130) >>> datetime.datetime.utcnow() datetime.datetime(2015, 11, 17, 17, 20, 7, 707990)
I'm still wondering why this would / could happen in the first place, so if anyone has any additional information, that would be great. Unfortunately, I do not know if I can reproduce it ...