You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Subsequent datetime.now() calls return the same datetime #124832
On Windows, time() now uses the GetSystemTimePreciseAsFileTime() clock for a resolution of 1 microsecond, instead of the GetSystemTimeAsFileTime() clock which has a resolution of 15.6 milliseconds. (Contributed by Victor Stinner in gh-63207.)
On Python 3.12, it's more likely that two consecutive calls to datetime.now() gives the same microseconds.
A warning that due to the clock resolution it's possible that two datetime.now() calls can return the same time even though a "substantial" amount of time has passed.
I had some tests failing which check that a datetime value which was updated was in the future.
That failed and I could not figure out why. I supplied UTC as tz because the docs mention it might increase precision but with no success.
A warning or hint would have been nice which I tried to add in the PR.
Activity
vstinner commentedon Oct 1, 2024
Test with Python 3.13, it got better clocks: https://docs.python.org/dev/whatsnew/3.13.html#time
On Python 3.12, it's more likely that two consecutive calls to datetime.now() gives the same microseconds.
vstinner commentedon Oct 1, 2024
It's not a bug.
What do you expect in the doc?
spacemanspiff2007 commentedon Oct 1, 2024
I understand and suspected as much.
A warning that due to the clock resolution it's possible that two
datetime.now()calls can return the same time even though a "substantial" amount of time has passed.I had some tests failing which check that a datetime value which was updated was in the future.
That failed and I could not figure out why. I supplied
UTCas tz because the docs mention it might increase precision but with no success.A warning or hint would have been nice which I tried to add in the PR.
gh-124832: Add a note to indicate that `datetime.now` may return the …
pythongh-124832: Add a note to indicate that `datetime.now` may retur…
pythongh-124832: Add a note to indicate that `datetime.now` may retur…
[3.13] gh-124832: Add a note to indicate that `datetime.now` may retu…
[3.12] gh-124832: Add a note to indicate that `datetime.now` may retu…
pythongh-124832: Add a note to indicate that `datetime.now` may retur…