[mod_python] mod_python + apache + winxp => could notimportmod_python.apache

Graham Dumpleton grahamd at dscpl.com.au
Sun Apr 9 20:28:53 EDT 2006


Graham Dumpleton wrote ..
> 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.

Here is a better version. If it fails on version match, will dump out:

[Mon Apr 10 10:24:02 2006] [error] python_init: Version mismatch, expected 2.3.5, found 2.3.
[Mon Apr 10 10:24:02 2006] [error] python_init: Executable '/usr/bin/python'.
[Mon Apr 10 10:24:02 2006] [error] python_init: Using Path '/Users/grahamd/lib/python:/System/Library/Frameworks/Python.framework/Versions/2.3/lib/python23.zip:/System/Library/Frameworks/Python.framework/Versions/2.3/lib/python2.3/:/System/Library/Frameworks/Python.framework/Versions/2.3/lib/python2.3/plat-darwin:/System/Library/Frameworks/Python.framework/Versions/2.3/lib/python2.3/plat-mac:/System/Library/Frameworks/Python.framework/Versions/2.3/lib/python2.3/plat-mac/lib-scriptpackages:/System/Library/Frameworks/Python.framework/Versions/2.3/lib/python2.3/lib-tk:/System/Library/Frameworks/Python.framework/Versions/2.3/lib/python2.3/lib-dynload'.

Patch is as follows. The question is, should mod_python output both
these values all the time?

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,23 @@
 
     /* 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);
+        ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, 0, s,
+                     "python_init: Executable '%s'.",
+                     Py_GetProgramFullPath());
+        ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, 0, s,
+                     "python_init: Using Path '%s'.",
+                     Py_GetPath());
+    }
+
     /* 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 */


Graham



More information about the Mod_python mailing list