Ich glaube, das ist eine bekannte Einschränkung der Python 2.7 Implementierung unter Windows:
>>> import datetime
>>> datetime.datetime.now()
datetime.datetime(2016, 8, 9, 10, 50, 59, 657000)
>>> datetime.datetime.now()
datetime.datetime(2016, 8, 9, 10, 51, 1, 561000)
>>> datetime.datetime.now()
datetime.datetime(2016, 8, 9, 10, 51, 2, 314000)
>>> datetime.datetime.now()
datetime.datetime(2016, 8, 9, 10, 51, 2, 906000)
>>> datetime.datetime.now()
datetime.datetime(2016, 8, 9, 10, 51, 9, 277000)
Siehe zum Beispiel here und here.
Im Quellcode Python 2.7, die Funktion Modules/datetimemodule.c/datetime_now()
schließlich Modules/timemodule.c/floattime()
aufruft, die den folgenden Kommentar hat:
/* There are three ways to get the time:
(1) gettimeofday() -- resolution in microseconds
(2) ftime() -- resolution in milliseconds
(3) time() -- resolution in seconds
In all cases the return value is a float in seconds.
Since on some systems (e.g. SCO ODT 3.0) gettimeofday() may
fail, so we fall back on ftime() or time().
Note: clock resolution does not imply clock accuracy! */
die Windows-Plattform So offensichtlich ftime()
wird mit der aktuellen Zeit und zu erhalten, da pro the MSDN page for _ftime()
(wo es ohne Zweifel endet), sind keine Mikrosekunden verfügbar. Deshalb 2.7 Python nur gibt Ihnen die Millisekunden und läßt die Mikrosekunden als Null:
return (double)t.time + (double)t.millitm * (double)0.001;
Python 3.5 erscheint eine vollständige Mikrosekunde Auflösung zu haben, so dass Sie berücksichtigen, dass sollten Schalen (als ob die große Anzahl von anderen Verbesserungen waren nicht genug).
Es könnte sich um ein Betriebssystemproblem handeln. hier auf LMDE Betsy (Linux) 64-Bit und Python 2.7.9 Ich kann Mikrosekunden bekommen: 'datetime.datetime (2016, 8, 9, 12, 46, 14, 209624)' –
Hier ist die Ausgabe von 'OS X' mit Python 2.7.10: 'datetime.datetime (2016, 8, 8, 19, 49, 23, 952833)'. In Windoze bekomme ich 'datetime.datetime '(2016, 8, 8, 19, 49, 23, 952000)' ... also würde ich sagen, Fred hat es genagelt. –
Relevant: http://stackoverflow.com/questions/1938048/high-precision-clock-in-python, http://stackoverflow.com/questions/16507924/bad-microsecond-resolution-in-python – Amadan