Google Mail Calendar Documents Reader Web more »
Recently Visited Groups | Help | Sign in
Google Groups Home
module imports and st_mtime
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  3 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Follow-up To:
Add Cc | Add Follow-up to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers that you hear
 
tow  
View profile   Translate to Translated (View Original)
 More options 5 Nov, 00:08
Newsgroups: comp.lang.python
From: tow <toby.o.h.wh...@googlemail.com>
Date: Wed, 4 Nov 2009 16:08:20 -0800 (PST)
Local: Thurs 5 Nov 2009 00:08
Subject: module imports and st_mtime
I'm seeing a very strange effect which is confusing me - in brief, one
python process appears to temporarily affect the os.stat results of
another - perhaps someone can enlighten me.

This is on Mac OS X Leopard, using the system python (2.5)

The issue arises using Django. The default Django http server runs a
watcher thread, which checks if any code is changing, and reloads
itself. It does this by iterating over all loaded modules, and
checking the mtime of each __file__. This was behaving oddly, and
finding out why exposed this strangeness. (The relevant code is in
django/utils/autoreload.py)

Some of the code running under this django server imports simplejson,
the C-implemented module of which has been put at /Users/tow/.python-
eggs/simplejson-2.0.9-py2.5-macosx-10.5-i386.egg-tmp/simplejson/
_speedups.so

This hasn't been touched since it was installed:

ls -l ~/.python-eggs/simplejson-2.0.9-py2.5-macosx-10.5-i386.egg-tmp/
simplejson/_speedups.so
-rwxr-xr-x  1 tow  staff  77596 12 Aug 17:56 /Users/tow/.python-eggs/
simplejson-2.0.9-py2.5-macosx-10.5-i386.egg-tmp/simplejson/
_speedups.so

If I check the mtime of that file from within django, it finds it
correctly:

print datetime.datetime.utcfromtimestamp(os.stat("/Users/tow/.python-
eggs/simplejson-2.0.9-py2.5-macosx-10.5-i386.egg-tmp/simplejson/
_speedups.so").st_mtime)
2009-08-12 17:56:02

The strange effect occurs when I open another python process, and
import simplejson there as well. As soon as I've done that, the mtime
that Django sees slips by an hour:

print datetime.datetime.utcfromtimestamp(os.stat("/Users/tow/.python-
eggs/simplejson-2.0.9-py2.5-macosx-10.5-i386.egg-tmp/simplejson/
_speedups.so").st_mtime)
2009-08-12 16:56:02

In fact, to be precise, this happens  as soon as the
simplejson._speedups module *finishes* being imported. (Tested by
stepping through every line with pdb)

The second Python process still sees the correct mtime, though, both
before and after it imports simplejson.

Restarting the Django process resets its view of the world, and it
sees the correct mtime again.

The current time as seen by the Django process is correct both before
and after the mtime slippage.

This seems to be 100% reproducible here, except for the time offset.
Usually it loses one hour, sometimes it gains 5 hours. (For what it's
worth, I'm currently on GMT, but the file was created during daylight
savings time).

I haven't managed to replicate it when the first process is something
other than Django. I've seen the effect on other Mac OS machines, but
haven't tested it on Linux so far. I've only seen the effect with
simplejson's C module, but I think this is the only C module which
might be being imported twice in this way for me.

Does anyone have any ideas what might be going on, or where further to
look? I'm at a bit of a loss.

Toby


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Carl Banks  
View profile   Translate to Translated (View Original)
 More options 5 Nov, 01:05
Newsgroups: comp.lang.python
From: Carl Banks <pavlovevide...@gmail.com>
Date: Wed, 4 Nov 2009 17:05:45 -0800 (PST)
Local: Thurs 5 Nov 2009 01:05
Subject: Re: module imports and st_mtime
On Nov 4, 4:08 pm, tow <toby.o.h.wh...@googlemail.com> wrote:

> Does anyone have any ideas what might be going on, or where further to
> look? I'm at a bit of a loss.

Does Mac OS have a concept of process-local filesystem modification?
I.e. when loading the library does it create a process-local copy of
the file with an updated timestamp?

Only thing I can think of, and if so it's probably not something you
want to turn off.

Carl Banks


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Aahz  
View profile   Translate to Translated (View Original)
 More options 10 Nov, 21:19
Newsgroups: comp.lang.python
From: a...@pythoncraft.com (Aahz)
Date: 10 Nov 2009 13:19:59 -0800
Local: Tues 10 Nov 2009 21:19
Subject: Re: module imports and st_mtime
In article <fb1b6b88-ccef-4f35-aaa9-b9d263969...@k19g2000yqc.googlegroups.com>,

tow  <toby.o.h.wh...@googlemail.com> wrote:

>Does anyone have any ideas what might be going on, or where further to
>look? I'm at a bit of a loss.

Try asking on pythonmac-...@python.org
--
Aahz (a...@pythoncraft.com)           <*>         http://www.pythoncraft.com/

[on old computer technologies and programmers]  "Fancy tail fins on a
brand new '59 Cadillac didn't mean throwing out a whole generation of
mechanics who started with model As."  --Andrew Dalke


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2009 Google