I have a quick issue with python's os.path.getmtime()
function. I have observed some weird behavior. I am working on a web app that checks periodically to see if a certain file has been modified and decides whether or not to refresh based on that.
In my local python command line, when I change the file and call os.path.getmtime(file_name)
the return value from mtime
has changed to reflect the change in the file.
However, when I call os.path.getmtime()
in my web app the return value before and after the change is the same. I did some research online and found some stuff to suggest that the os module needs to be reloaded for the change to the file to be registered. So, in my web app I reloaded the os
module, but mtime
still does not reflect changes to the file. Has anyone else encountered this problem before or know a solution? I have included a code snippet below from the webapp:
import os
def function_name():
reload(os)
file_path = '/dir/lib/some_file.js'
try:
mtime = os.path.getmtime(file_path)
except os.error:
pass
return mtime