[mod_python] ImportError: reload(): module ... not in sys.modules ?

Graham Dumpleton graham.dumpleton at gmail.com
Thu Aug 30 19:23:54 EDT 2007


On 31/08/2007, liamr at umich.edu <liamr at umich.edu> wrote:
> So you'd say this is due to a fundamental change in behavior between
> 3.3.1 and 3.2.10?

Depends on how you look at it. Using reload() explicitly isn't
necessary a reliable way of doing things in the first place when using
mod_python and would in general not be recommended.

The import_module() function does actually exist in older versions of
mod_python and if they use it, their code should be reasonably
portable between the versions. They should base their use of the
function on older documentation though as newer version provides
additional features and if they were relied upon the code wouldn't be
backward compatible.

What occurred in 3.3.1 is that the implementation of import_module()
was completed redone to fix a range of problems:

  http://www.dscpl.com.au/wiki/ModPython/Articles/ModuleImportingIsBroken

The changes created a few incompatibilities, but it would only affect
a very small percentage of people. That reload() will now not work on
modules managed by the mod_python module importer is one.

If you want to restore the old module importer functionality without
downgrading mod_python, then you can also set the
'mod_python.legacy.importer' option as described in the documentation
for 'import_module()'.

> Might the version difference also explain..
>
> File "/usr/lib/python2.5/xml/sax/handler.py", line 38, in fatalError
>     raise exception
>
>   SAXParseException:
>
>     https://example.umich.edu/pharmacy//lessonsdir/lesson.dtd:1:0:
>    error in processing external entity reference
>
> We're running into some other stuff that I figured may be due to his
> application being developed in a the 3.1 branch and us running the 3.3
> branch, but I'm not familiar enough with what's going on to know what
> I'm looking for the in the change log.

This latter issue looks more to be because of the difference in the
Python version than mod_python. Thus, you have more to contend with
than the differences in mod_python version and I'd contend that
mod_python version differences will actually be the lessor of your
problems.

Graham

> Quoting Graham Dumpleton <graham.dumpleton at gmail.com>:
>
> > Quick fix is to comment out the line with 'reload()' on it.
> >
> > Beyond that you have two options:
> >
> > 1. Downgrade from mod_python 3.3.1 to 3.2.10.
> >
> > 2. Have the author of the application upgrade to 3.3.1 and have them
> > fix their code to eliminate use of reload() which will not work with
> > modules in 3.3.1 managed by mod_python and was never a reliable way in
> > older versions of mod_python of reloading modules anyway. To assist
> > them in fixing their code when they move to 3.3.1, point them to the
> > function 'import_module()' in the documentation:
> >
> >  http://www.modpython.org/live/current/doc-html/pyapi-apmeth.html
> >
> > That function is the correct way in mod_python of managing reloading
> > of mod_python managed modules.
> >
> > Graham
> >
> > On 30/08/2007, Liam Hoekenga <liamr at umich.edu> wrote:
> >> I'm a sysadmin who's part of a group that provides campus-wide web hosting
> >> at our university.  We're working with a faculty member who would like us
> >> to host an application he wrote in his departmental web environment and
> >> we're having issues.  Of course the application "just works" on his
> >> departmental machine, but when we try it on our box, the most current
> >> error we're getting is...
> >>
> >>         ImportError: reload(): module _mp_a52d922604fbb12687f4374d3c536a1b
> >>                 not in sys.modules
> >>
> >> Their departmental server is  using Apache 2.0.52, Python 2.3.4 and
> >> mod_python 3.1.3.
> >>
> >> We're using Apache 2.2.3, Python 2.5, and mod_python 3.3.1.
> >>
> >> I'm not a python programmer and this is my first forray in to mod_python.
> >> It kind of looks like from the rest of the debugging output that
> >> _mp_a52d922604fbb12687f4374d3c536a1b is the name of a "file" that
> >> mod_python has already processed an inserted into a cache.. and that
> >> perhaps that cache isn't in the python path?  I don't know.  Kinda
> >> grasping at straws here.
> >>
> >> Here's our current mod_python configuration for the directory in question..
> >>
> >>      Alias /pharmacy/ /home/pharmacy/Private/html/
> >>     <IfModule mod_python.c>
> >>         <Directory /home/pharmacy/Private/html/>
> >>         AddHandler mod_python .py
> >>         AllowOverride AuthConfig FileInfo Indexes Limit
> >>         PythonAutoReload On
> >>         PythonHandler /home/pharmacy/Private/html/python-program.py
> >>         PythonDebug On
> >>         </Directory>
> >>      </IfModule>
> >>
> >> If it does look like problems due to differences between the environments
> >> in which the application was developed and the where we're trying to
> >> deploy it, I'd be very appreciative for hints at what needs to be changed
> >> to make it work.  I'm very open to suggestions.
> >>
> >> What follows are the excerpts from the apache error logs, and the output
> >> we see when we access the page with PythonDebug enabled.
> >>
> >> Liam
> >>
> >> --------------------------------------
> >>
> >> Here's the appropriate output from the apache error log...
> >>
> >> [Wed Aug 29 10:08:41 2007] [notice] mod_python (pid=6977,
> >> interpreter='example.umich.edu'): Importing module
> >> '/home/pharmacy/Private/html/python-program.py'
> >> [Wed Aug 29 10:08:41 2007] [notice] mod_python (pid=6977,
> >> interpreter='example.umich.edu'): Importing module
> >> '/home/pharmacy/Private/html/tutor.py'
> >> [Wed Aug 29 10:08:41 2007] [notice] mod_python (pid=6977,
> >> interpreter='example.umich.edu'): Importing module
> >> '/home/pharmacy/Private/html/lesson.py'
> >> [Wed Aug 29 10:08:41 2007] [notice] mod_python (pid=6977,
> >> interpreter='example.umich.edu'): Importing module
> >> '/home/pharmacy/Private/html/tex.py'
> >> [Wed Aug 29 10:08:45 2007] [error] [client xxx.xxx.xxx.xxx]
> >> mod_python (pid=6977, interpreter='example.umich.edu',
> >> phase='PythonHandler',
> >> handler='/home/pharmacy/Private/html/python-program.py'):
> >> Application error, referer:
> >> https://example.umich.edu/pharmacy/python-program.py
> >> [Wed Aug 29 10:08:45 2007] [error] [client xxx.xxx.xxx.xxx]
> >> ServerName: 'example.umich.edu', referer:
> >> https://example.umich.edu/pharmacy/python-program.py
> >> [Wed Aug 29 10:08:45 2007] [error] [client xxx.xxx.xxx.xxx]
> >> DocumentRoot: '/usr/share/apache2/htdocs/default/', referer:
> >> https://example.umich.edu/pharmacy/python-program.py
> >> [Wed Aug 29 10:08:45 2007] [error] [client xxx.xxx.xxx.xxx] URI:
> >> '/pharmacy/python-program.py', referer:
> >> https://example.umich.edu/pharmacy/python-program.py
> >> [Wed Aug 29 10:08:45 2007] [error] [client xxx.xxx.xxx.xxx]
> >> Location: None, referer:
> >> https://example.umich.edu/pharmacy/python-program.py
> >> [Wed Aug 29 10:08:45 2007] [error] [client xxx.xxx.xxx.xxx]
> >> Directory: '/home/pharmacy/Private/html/', referer:
> >> https://example.umich.edu/pharmacy/python-program.py
> >> [Wed Aug 29 10:08:45 2007] [error] [client xxx.xxx.xxx.xxx]
> >> Filename: '/home/pharmacy/Private/html/python-program.py', referer:
> >> https://example.umich.edu/pharmacy/python-program.py
> >> [Wed Aug 29 10:08:45 2007] [error] [client xxx.xxx.xxx.xxx]
> >> PathInfo: '', referer:
> >> https://example.umich.edu/pharmacy/python-program.py
> >> [Wed Aug 29 10:08:45 2007] [error] [client xxx.xxx.xxx.xxx]
> >> Traceback (most recent call last):, referer:
> >> https://example.umich.edu/pharmacy/python-program.py
> >> [Wed Aug 29 10:08:45 2007] [error] [client xxx.xxx.xxx.xxx]   File
> >> "/usr/lib/python2.5/site-packages/mod_python/importer.py", line
> >> 1537, in HandlerDispatch\n    default=default_handler, arg=req,
> >> silent=hlist.silent), referer:
> >> https://example.umich.edu/pharmacy/python-program.py
> >> [Wed Aug 29 10:08:45 2007] [error] [client xxx.xxx.xxx.xxx]   File
> >> "/usr/lib/python2.5/site-packages/mod_python/importer.py", line
> >> 1229, in _process_target\n    result = _execute_target(config, req,
> >> object, arg), referer:
> >> https://example.umich.edu/pharmacy/python-program.py
> >> [Wed Aug 29 10:08:45 2007] [error] [client xxx.xxx.xxx.xxx]   File
> >> "/usr/lib/python2.5/site-packages/mod_python/importer.py", line
> >> 1128, in _execute_target\n    result = object(arg), referer:
> >> https://example.umich.edu/pharmacy/python-program.py
> >> [Wed Aug 29 10:08:45 2007] [error] [client xxx.xxx.xxx.xxx]   File
> >> "/home/pharmacy/Private/html/python-program.py", line 224, in
> >> handler\n    s = coord.initHistory(session, formd), referer:
> >> https://example.umich.edu/pharmacy/python-program.py
> >> [Wed Aug 29 10:08:45 2007] [error] [client xxx.xxx.xxx.xxx]   File
> >> "/home/pharmacy/Private/html/python-program.py", line 132, in
> >> initHistory\n    reload(tutor)\t# Force the current version of tutor
> >> module to be used., referer:
> >> https://example.umich.edu/pharmacy/python-program.py
> >> [Wed Aug 29 10:08:45 2007] [error] [client xxx.xxx.xxx.xxx]
> >> ImportError: reload(): module _mp_a52d922604fbb12687f4374d3c536a1b
> >> not in sys.modules, referer:
> >> https://example.umich.edu/pharmacy/python-program.py
> >>
> >> --------------------------------------
> >>
> >> Here's what we get when we access the page with PythonDebug turned on...
> >>
> >> ...continuing old session
> >>
> >> ...POST reading: uniqname=bjensen&lessonchoice=Minimal&startup=Start
> >> ...cwd='/'
> >> ...ls=['lost+found', 'var', '.bash_history', '.authorize', 'afs',
> >> 'bin', 'boot', 'dev',
> >> 'etc', 'home', 'lib', 'mnt', 'proc', 'root',  'sys', 'sbin',
> >> 'ticket', 'tmp', 'usr',
> >> 'opt', 'man']
> >> MOD_PYTHON ERROR
> >>
> >> ProcessId:      22409
> >> Interpreter:    'example.umich.edu'
> >>
> >> ServerName:     'example.umich.edu'
> >> DocumentRoot:   '/usr/share/apache2/htdocs/default/'
> >>
> >> URI:            '/pharmacy/python-program.py'
> >> Location:       None
> >> Directory:      '/home/pharmacy/Private/html/'
> >> Filename:       '/home/pharmacy/Private/html/
> >> crippen/python-program.py'
> >> PathInfo:       ''
> >>
> >> Phase:          'PythonHandler'
> >> Handler:        '/home/pharmacy/Private/html/
> >> crippen/python-program.py'
> >>
> >> Traceback (most recent call last):
> >>
> >>    File "/usr/lib/python2.5/site-packages/mod_python/importer.py",
> >> line 1537, in
> >> HandlerDispatch
> >>      default=default_handler, arg=req, silent=hlist.silent)
> >>
> >>    File "/usr/lib/python2.5/site-packages/mod_python/importer.py",
> >> line 1229, in
> >> _process_target
> >>      result = _execute_target(config, req, object, arg)
> >>
> >>    File "/usr/lib/python2.5/site-packages/mod_python/importer.py",
> >> line 1128, in
> >> _execute_target
> >>      result = object(arg)
> >>
> >>    File "/home/pharmacy/Private/html python-program.py",
> >> line 224, in handler
> >>      s = coord.initHistory(session, formd)
> >>
> >>    File "/home/pharmacy/Private/html python-program.py",
> >> line 132, in initHistory
> >>      reload(tutor)        # Force the current version of tutor
> >> module to be  used.
> >>
> >> ImportError: reload(): module _mp_a52d922604fbb12687f4374d3c536a1b
> >> not in sys.modules
> >>
> >>
> >> MODULE CACHE DETAILS
> >>
> >> Accessed:       Tue Aug 28 17:47:07 2007
> >> Generation:     4
> >>
> >> _mp_036881b8bfdae0dbd53cd31522b8613c {
> >>    FileName:     '/home/pharmacy/Private/html/ crippen/lesson.py'
> >>    Instance:     1
> >>    Generation:   1
> >>    Modified:     Wed Mar  7 13:53:05 2007
> >>    Imported:     Tue Aug 28 17:26:23 2007
> >> }
> >>
> >> _mp_6e0a86c977aa7b4821de3f2e456eeb4d {
> >>    FileName:     '/home/pharmacy/Private/html/
> >> crippen/python-program.py'
> >>    Instance:     1
> >>    Generation:   4
> >>    Modified:     Tue Aug 28 17:26:02 2007
> >>    Imported:     Tue Aug 28 17:26:23 2007
> >>    ModulePath:   '/home/pharmacy/Private/html/'
> >>    Children:     '/home/pharmacy/Private/html/ crippen/tutor.py'
> >> }
> >>
> >> _mp_251123f760a2485b75c77026f93acd83 {
> >>    FileName:     '/home/pharmacy/Private/html/ crippen/tex.py'
> >>    Instance:     1
> >>    Generation:   2
> >>    Modified:     Fri Mar 30 09:39:23 2007
> >>    Imported:     Tue Aug 28 17:26:23 2007
> >> }
> >>
> >> _mp_a52d922604fbb12687f4374d3c536a1b {
> >>    FileName:     '/home/pharmacy/Private/html/ crippen/tutor.py'
> >>    Instance:     1
> >>    Generation:   3
> >>    Modified:     Tue Aug 21 15:16:35 2007
> >>    Imported:     Tue Aug 28 17:26:23 2007
> >>    Children:     '/home/pharmacy/Private/html/ crippen/lesson.py',
> >>                  '/home/pharmacy/Private/html/ crippen/tex.py'
> >> }
> >>
> >> _______________________________________________
> >> Mod_python mailing list
> >> Mod_python at modpython.org
> >> http://mailman.modpython.org/mailman/listinfo/mod_python
> >>
> >
> > !DSPAM:46d5f1ac113225939618124!
> >
> >
> >
> >
>
>
>


More information about the Mod_python mailing list