Consider this simple Python script:
$ cat test_utc.py
from datetime import datetime
for i in range(10_000_000):
first = datetime.utcnow()
second = datetime.utcnow()
assert first <= second, f"{first=} {second=} {i=}"
When I run it from the shell like python test_utc.py it finishes w/o errors, just as expected. However, when I run it in a Docker container the assertion fails:
$ docker run -it --rm -v "$PWD":/code -w /code python:3.10.4 python test_utc.py
Traceback (most recent call last):
File "/code/test_utc.py", line 7, in <module>
assert first <= second, f"{first=} {second=} {i=}"
AssertionError: first=datetime.datetime(2022, 5, 24, 19, 5, 1, 861308) second=datetime.datetime(2022, 5, 24, 19, 5, 1, 818270) i=1818860
How is it possible?
P.S. a colleague has reported that increasing the range parameter to 100_000_000 makes it fail in the shell on their mac as well (but not for me).