Following test is always failing (this runs on a linux system, the question is not about other OSes):
from time import time
from decimal import Decimal
from pathlib import Path
def test_timing():
start = Decimal(time())
p = Path(__file__).parent / 'testfile.txt' # does not yet exist
p.touch()
mt = p.stat().st_mtime
p.unlink() # unlinked before the failing assert
> assert start <= mt
E AssertionError: assert Decimal('1640930671.75709438323974609375') <= 1640930671.7534654
The gap is always about 3 to 7 ms.
How is it possible that Decimal(time())
at start returns a timestamp that’s later than the file that is created two lines after it?
Is there an offset between python timestamps and the linux’ ones? Does python proceed creating the file before the Decimal(time())
call is finished? What am I missing here?
EDIT: I should have mentionned it’s ext4 filesystem.