[mod_python] persistent values

Sean Reifschneider jafo at tummy.com
Mon Jun 23 16:56:38 EST 2003


On Mon, Jun 23, 2003 at 06:31:47PM -0400, Gregory (Grisha) Trubetskoy wrote:
>There isn't anything unusual about the way mod_python imports modules.

Someone on this list replied to one of my earlier messages and said that
mod_python hooks into the import mechanism for some reason.

There definitely are issues related to importing of packages...  From
mod_python, if I import a package that has a module within it, I can't
access that name unless the package __init__.py imports that name.  For
example, the following works from Python:

   guin:p$ mkdir pkg
   guin:p$ echo >pkg/__init__.py
   guin:p$ echo 'foo = "bar"' >pkg/baz.py
   guin:p$ python -c 'from pkg import baz; print baz.foo'
   bar
   guin:p$

IIRC, in mod_python that would give me an AttributeError on the "from
pkg import baz", unless I do:

   echo 'import baz' >pkg/__init__.py

Of course, this means that my entire package structure must be imported
through the __init__.py files, even if not all of it is used.  Worse,
this means that I can't have a module which imports another module, that
imports the first module...

>PythonAutoReload can yeld strange results after a lot of changes and a lot
>of reloading, but that's not unusual during development. A cleanly started
>Apache should (and does for me at least) behave 100% predictably.

That's not been my experience, where "predictably" is defined as
"behaving as I expect Python code to".  I mean, it's predictable in it's
unpredictability.  ;-)

Sean
-- 
 What we see depends on mainly what we look for.
                 -- John Lubbock
Sean Reifschneider, Member of Technical Staff <jafo at tummy.com>
tummy.com, ltd. - Linux Consulting since 1995.  Qmail, Python, SysAdmin


More information about the Mod_python mailing list