Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

223
Views
File seems to be timestamped before it is created

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.

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

The ext4 filesystem uses current_fs_time to grab the kernel timestamp. For efficiency, the kernel timestamp is a cached value, which is only updated at scheduler intervals, which is about 10ms. So, the time could be as much as 10ms old by the time it gets stored.

As a side note, there is no point in converting the timestamp to Decimal. The value from C is a double, which only holds about 17 digits. That means you get down to microseconds. Converting to Decimal does not gain you any additional precision; the other digits are essentially random.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!