You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Support st_atim, st_mtim and st_ctim attributes in os.stat_result #56150
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
assignee=Noneclosed_at=<Date2012-02-26.22:01:36.328>created_at=<Date2011-04-27.21:00:15.746>labels= ['type-feature']
title='Support st_atim, st_mtim and st_ctim attributes in os.stat_result'updated_at=<Date2012-02-26.22:01:36.326>user='https://bugs.python.org/Arfrever'
I would like to suggest to add st_atim, st_mtim and st_ctim attributes in os.stat_result objects returned by os.stat(). These attributes would be 2-tuples containing number of seconds and number of nanoseconds. They would expose relevant functionality from libc's stat() and provide better precision than floating-point-based st_atime, st_mtime and st_ctime attributes.
st_atim, st_mtim and st_ctim attributes would be available only if Python has been built on system with libc supporting st_atim, st_mtim and st_ctim in stat structure.
Actually issue bpo-11941 should be a dependency of issue bpo-11457. Issue bpo-11941 is only about os.stat(), while issue bpo-11457 proposes changes also in other places (e.g. tarfile module).
I'm not sure if that's deliberate, but the new attributes don't appear in the result repr():
>>> s = os.stat("LICENSE")
>>> s
posix.stat_result(st_mode=33204, st_ino=524885, st_dev=2053, st_nlink=1, st_uid=500, st_gid=500, st_size=14597, st_atime=1307474138, st_mtime=1299630588, st_ctime=1299630588)
>>> s.st_mtim
(1299630588, 90781883)
In the docs, you also need a "versionchanged" tag to mention that the attributes were added in 3.3.
The patch fails to compile under Windows: MSVC forbids variable declarations after code (atim, ctim, mtim), you have to put them at the beginning of a block. Once this is fixed, it seems to work ok.
Given Guido's rejection of PEP-410, this won't happen, so I'm closing this bug. Our BFDL has specifically rejected any of the complicated representations; he ruled that all we need are new _ns fields representing the time in nanoseconds, and to accept a "ns=" argument for os.utime and its ilk. Please see bug bpo-14127 for discussion of that change.
Activity
Arfrever commentedon Apr 27, 2011
I would like to suggest to add st_atim, st_mtim and st_ctim attributes in os.stat_result objects returned by os.stat(). These attributes would be 2-tuples containing number of seconds and number of nanoseconds. They would expose relevant functionality from libc's stat() and provide better precision than floating-point-based st_atime, st_mtime and st_ctime attributes.
st_atim, st_mtim and st_ctim attributes would be available only if Python has been built on system with libc supporting st_atim, st_mtim and st_ctim in stat structure.
http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/sys_stat.h.html
http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/time.h.html
rosslagerwall commentedon Apr 28, 2011
I think this is a duplicate of bpo-11457.
Arfrever commentedon Apr 28, 2011
Actually issue bpo-11941 should be a dependency of issue bpo-11457. Issue bpo-11941 is only about os.stat(), while issue bpo-11457 proposes changes also in other places (e.g. tarfile module).
rosslagerwall commentedon Apr 28, 2011
Ok, that's true, reopening.
rosslagerwall commentedon Jun 3, 2011
Attached is a patch for review.
It adds st_atim, st_ctim and st_mtim.
They are defined even when the underlying system does not have nanosecond precision.
Arfrever commentedon Jun 3, 2011
rosslagerwall commentedon Jun 8, 2011
Here is an updated patch that uses the atim, ctim and mtim variables (which are assigned based on various #ifdefs).
This should now work on Linux, BSD and Windows.
pitrou commentedon Jun 8, 2011
I'm not sure if that's deliberate, but the new attributes don't appear in the result repr():
In the docs, you also need a "versionchanged" tag to mention that the attributes were added in 3.3.
The patch fails to compile under Windows: MSVC forbids variable declarations after code (atim, ctim, mtim), you have to put them at the beginning of a block. Once this is fixed, it seems to work ok.
larryhastings commentedon Feb 26, 2012
Given Guido's rejection of PEP-410, this won't happen, so I'm closing this bug. Our BFDL has specifically rejected any of the complicated representations; he ruled that all we need are new _ns fields representing the time in nanoseconds, and to accept a "ns=" argument for os.utime and its ilk. Please see bug bpo-14127 for discussion of that change.