> If I run your snippet and inspect modification times using `stat`, the > difference is much smaller (around 10 ns, not 1 ms): > > $ stat test | \grep Modify > Modify: 2012-02-16 13:51:25.643597139 +0100 > $ stat test2 | \grep Modify > Modify: 2012-02-16 13:51:25.643597126 +0100
The loss of precision is not constant: it depends on the timestamp value. Another example using the stat program: ------------ import decimal, os, shutil, time try: os.unlink("test") except OSError: pass try: os.unlink("test2") except OSError: pass open("test", "x").close() shutil.copy2("test", "test2") print(os.stat("test", timestamp=decimal.Decimal).st_mtime) print(os.stat("test2", timestamp=decimal.Decimal).st_mtime) print(os.stat("test2", timestamp=decimal.Decimal).st_mtime - os.stat("test", timestamp=decimal.Decimal).st_mtime) os.system("stat test|grep ^Mod") os.system("stat test2|grep ^Mod") ------------ Outputs: ------------ $ ./python x.py 1329398229.918858600 1329398229.918208829 -0.000649771 Modify: 2012-02-16 14:17:09.918858600 +0100 Modify: 2012-02-16 14:17:09.918208829 +0100 $ ./python x.py 1329398230.862858588 1329398230.861343658 -0.001514930 Modify: 2012-02-16 14:17:10.862858588 +0100 Modify: 2012-02-16 14:17:10.861343658 +0100 $ ./python x.py 1329398232.450858570 1329398232.450067044 -0.000791526 Modify: 2012-02-16 14:17:12.450858570 +0100 Modify: 2012-02-16 14:17:12.450067044 +0100 $ ./python x.py 1329398233.090858561 1329398233.090853761 -0.000004800 Modify: 2012-02-16 14:17:13.090858561 +0100 Modify: 2012-02-16 14:17:13.090853761 +0100 ------------ The loss of precision is between 1 ms and 4 us. Decimal timestamps display exactly the same value than the stat program: I don't see any bug in this example. Victor PS: Don't try os.utime(Decimal) with my patch, the conversion from Decimal to _PyTime_t does still use float internally (I know this issue, it should be fixed in my patch) and so loss precision ;-) _______________________________________________ Python-Dev mailing list Python-Dev@python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com