[mod_python] mod_python + apache + winxp => could not importmod_python.apache

Graham Dumpleton grahamd at dscpl.com.au
Sun Apr 9 20:07:03 EDT 2006


Jim Gallacher wrote ..
> cyberco wrote:
> >   On my system:
> > 
> > =============
> > mod_python 3.2.8
> > apache 2.0.55
> > python2.4
> > winxp
> > =============
>
> ...
>
> > - At starup the Apache log states:
> > [Sun Apr 09 22:16:38 2006] [notice] Apache/2.0.55 (Win32) mod_python/3.2.5b
> > Python/2.4.2 configured -- resuming normal operations
> 
> It may just be a typo in your message, and even if not it may not be 
> significant, but I notice that you say you are using mod_python 3.2.8 
> but the apache log is showing version 3.2.5b. It might be worth 
> investigating.

As a start for some internal self debugging by mod_python, how about
we make the following change:

Index: src/mod_python.c
===================================================================
--- src/mod_python.c    (revision 392846)
+++ src/mod_python.c    (working copy)
@@ -575,6 +575,9 @@
     const char *userdata_key = "python_init";
     apr_status_t rc;
 
+    const char *py_compile_version = PY_VERSION;
+    const char *py_dynamic_version = 0;
+
     /* The "initialized" flag is a fudge for Mac OS X. It
      * addresses two issues. The first is that when an Apache
      * "restart" is performed, Apache will unload the mod_python
@@ -599,9 +602,17 @@
 
     /* mod_python version */
     ap_add_version_component(p, VERSION_COMPONENT);
-    
+
+    py_dynamic_version = strtok((char *)Py_GetVersion(), " ");
+
+    if (strcmp(py_compile_version, py_dynamic_version) != 0) {
+        ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, 0, s,
+                     "python_init: Version mismatch, expected %s, found %s.",
+                     py_compile_version, py_dynamic_version);
+    }
+
     /* Python version */
-    sprintf(buff, "Python/%.200s", strtok((char *)Py_GetVersion(), " "));
+    sprintf(buff, "Python/%.200s", py_dynamic_version);
     ap_add_version_component(p, buff);
 
     /* cache main server */

Will this work, reliably across Python on different platforms? I think
it should as long as PyGetVersion() implementation hasn't changed
at some point.

There are some other points in code where other checks or debug
could be output. For example, if mod_python Python modules can't
be found, then dumpy out sys.path.

Even for the above, would be nice to dump out where Python thinks
it lives when such a mismatch occurs, as would highlight where
wrong version is coming from. Just need to work out a good way
of determining this, may need to wait until after Python has been
initialised though.

Graham


More information about the Mod_python mailing list