os.stat and strange st_ctime

Mark Jones mark0978 at gmail.com
Mon Oct 11 00:59:05 EDT 2010


I've read the part about these being variable

Note


The exact meaning and resolution of the st_atime, st_mtime, andst_ctime members
depends on the operating system and the file system. For example, on Windows
systems using the FAT or FAT32 file systems, st_mtimehas 2-second
resolution, and st_atime has only 1-day resolution. See your operating
system documentation for details.


However, given the fact that NTFS supports 100ns resolution, the results
here just look wrong.  st_ctime doesn't show a different time until there is
a ~15 second gap in the creation times (then however is shows the full time
gap)  Notice

Linux doesn't do this, the times look normal.  Seems strange to break cross
platform compatibility like this...


Here is the test code:

import os
import time

def runtest(sleepSecs):
print "Sleeping: " + str(sleepSecs)

fA = open("A", "w")
fA.close();

if sleepSecs:
time.sleep(sleepSecs)

fB = open("B", "w")
fB.close();
 info = os.stat("A")
print "A:",info.st_ctime, info.st_mtime, info.st_atime
 info = os.stat("B")
print "B:",info.st_ctime, info.st_mtime, info.st_atime

os.remove("A")
os.remove("B")


When run under Win7 on NTFS

for i in range(1,20):
  runtest(i)

>>> for i in range(0,20):
...   stattest.runtest(i)
...
Sleeping: 0
A: 1286770829.44 1286770829.44 1286770829.44
B: 1286770829.44 1286770829.44 1286770829.44
Sleeping: 1
A: 1286770829.44 1286770829.44 1286770829.44
B: 1286770829.44 1286770830.44 1286770830.44
Sleeping: 2
A: 1286770829.44 1286770830.45 1286770830.45
B: 1286770829.44 1286770832.45 1286770832.45
Sleeping: 3
A: 1286770829.44 1286770832.46 1286770832.46
B: 1286770829.44 1286770835.46 1286770835.46
Sleeping: 4
A: 1286770829.44 1286770835.47 1286770835.47
B: 1286770829.44 1286770839.47 1286770839.47
Sleeping: 5
A: 1286770829.44 1286770839.48 1286770839.48
B: 1286770829.44 1286770844.48 1286770844.48
Sleeping: 6
A: 1286770829.44 1286770844.49 1286770844.49
B: 1286770829.44 1286770850.49 1286770850.49
Sleeping: 7
A: 1286770829.44 1286770850.5 1286770850.5
B: 1286770829.44 1286770857.5 1286770857.5
Sleeping: 8
A: 1286770829.44 1286770857.51 1286770857.51
B: 1286770829.44 1286770865.51 1286770865.51
Sleeping: 9
A: 1286770829.44 1286770865.52 1286770865.52
B: 1286770829.44 1286770874.52 1286770874.52
Sleeping: 10
A: 1286770829.44 1286770874.52 1286770874.52
B: 1286770829.44 1286770884.53 1286770884.53
Sleeping: 11
A: 1286770829.44 1286770884.56 1286770884.56
B: 1286770829.44 1286770895.56 1286770895.56
Sleeping: 12
A: 1286770829.44 1286770895.57 1286770895.57
B: 1286770829.44 1286770907.57 1286770907.57
Sleeping: 13
A: 1286770829.44 1286770907.58 1286770907.58
B: 1286770829.44 1286770920.58 1286770920.58
Sleeping: 14
A: 1286770829.44 1286770920.59 1286770920.59
B: 1286770829.44 1286770934.59 1286770934.59
*Sleeping: 15*
*A: 1286770829.44 1286770934.6 1286770934.6*
*B: 1286770949.6 1286770949.6 1286770949.6*
Sleeping: 16
A: 1286770829.44 1286770949.61 1286770949.61
B: 1286770965.61 1286770965.61 1286770965.61
Sleeping: 17
A: 1286770829.44 1286770965.62 1286770965.62
B: 1286770982.62 1286770982.62 1286770982.62
Sleeping: 18
A: 1286770829.44 1286770982.63 1286770982.63
B: 1286771000.63 1286771000.63 1286771000.63
Sleeping: 19
A: 1286770829.44 1286771000.63 1286771000.63
B: 1286771019.63 1286771019.63 1286771019.63
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20101010/694a5335/attachment.html>


More information about the Python-list mailing list