views:

101

answers:

1

I compiled python 2.6.4 for centos 5.3 and find this issue that os.path.getmtime() or os.stat().m_time doesn't have the fraction part. As per docs, if os.stat_float_times() returns True, then it should return float value. In my case, I do see it as float, but no fraction part (it is 0).

In [3]: os.path.getmtime('/tmp') 
Out[3]: 1268339116.0

In [4]: os.stat('/tmp')
Out[4]: posix.stat_result(st_mode=17407, st_ino=508897L, st_dev=29952L, st_nlink=7, st_uid=0, st_gid=0, st_size=4096L, st_atime=1268101696, st_mtime=1268339116, st_ctime=1268339116)

In [5]: os.stat_float_times()
True

In [6]: os.stat('/tmp').st_mtime
Out[6]: 1268339116.0

It is also strange that the stat() output seems like an int. On windows, I do see a fraction part with the same python version. I am running centos on top of colinux, could that be playing a role, or is it some python build issue? I couldn't find any hits for generic colinux issue. May be it is how colinux configures the filesystem? What would I need to check in that case?

+4  A: 

This is a filesystem limitation, rather than a Python one. Centos is still on ext3, which provides integer mtimes. You can see this if you display the mtimes with ls. Try

ls -ld --full-time /tmp

On my ext3 Centos box, I get

drwxrwxrwt 11 root root 69632 2010-03-11 13:16:30.000000000 -0800 /tmp

On my ext4 Ubuntu box, I get

drwxrwxrwt 16 root root 20480 2010-03-11 21:20:02.088188962 +0000 /tmp

This is described in the ext4 Wikipedia article:

Improved timestamps

As computers become faster in general and as Linux becomes used more for mission critical applications, the granularity of second-based timestamps becomes insufficient. To solve this, ext4 provides timestamps measured in nanoseconds. In addition, 2 bits of the expanded timestamp field are added to the most significant bits of the seconds field of the timestamps to defer the year 2038 problem for an additional 204 years.

ire_and_curses
Thanks, that makes sense. I verified that the filesystem is ext3 and I didn't actually know that this is a limitation. This information would be helpful to either tune the program or may be decide to go with ext4 instead.
haridsv