[mod_python] questions/ideas

Johannes Erdfelt johannes at erdfelt.com
Mon May 13 14:12:24 EST 2002


On Mon, May 13, 2002, Michal Vitecek <fuf at mobil.cz> wrote:
>  i'm taking a decision whether to use python or php in my next project.
>  i'm leaning towards python and mod_python, but i found some
>  problems/questions/ideas that i'd like to know answers to first.

I've made the switch from PHP to mod_python successfully.

>     a) as i did my previous projects in php i now find it quite strange
>        that i need to call a certain function of a script. this makes it a
>        bit more difficult to use the few global variables that i plan to
>        use and from time to time makes the whole program into a single
>        function (one tab is taken)

That's just how python works. It's a different style of programming, but
I think it's better.

I got into too many problems with global variables in PHP that caused me
headaches.

>     b) the publisher submodule needs to know the name of the function to
>        run - would it be possible to change it so that it doesn't need it
>        ie. run the whole script instead?

Use the attached patch to mod_python. It'll call the function named
"handler" if there is no name passed. The patch is relative to 2.7.6.

>     c) the publisher submodule reads the whole output of a function to a
>        variable - for a sites with large html pages this could be 100s of
>        KBs. this could mean a noticeable performance slowdown - also
>        because the output must be prepared first. how about if the
>        function output the resulting html code to a stream?

Have you measured a decrease in performance?

>     d) i noticed that the python interpreter is not the same even for a
>        single virtualhost (even when i explicitly define its name with
>        PythonInterpreter) => the persistence is kept only withing every
>        apache child. with increase of the number of children a new
>        interpreter is created that doesn't inherit from the main one (i'm
>        using python 2.2.1 and apache 1.3.20).

That's because of the multiple process approach to apache. Since each
child is a different process, they don't share memory.

You can play tricks with shared memory if you really need that
functionality.

>     e) in php it's possible to have the php code mixed with the html one -
>        ie. there are special marks, that mark the start and end of php
>        code. i think it would be a nice option to have in mod_python
>        because it helps imho to create scripts the allow for easy to
>        review code.

There are add on packages like that. I've been using a package called
Cheetah that provides something similar.

Do some searching.

JE

-------------- next part --------------
--- mod_python/publisher.py.orig	Tue Apr 16 20:31:06 2002
+++ mod_python/publisher.py	Tue Apr 16 20:34:45 2002
@@ -80,17 +80,17 @@
     args = {}
 
     # get the path PATH_INFO (everthing after script)
-    if not _req.subprocess_env.has_key("PATH_INFO"):
-        raise apache.SERVER_RETURN, apache.HTTP_NOT_FOUND
-    
-    func_path = _req.subprocess_env["PATH_INFO"][1:] # skip fist /
-    func_path = string.replace(func_path, "/", ".")
-    if func_path[-1] == ".":
-        func_path = func_path[:-1] 
+    if _req.subprocess_env.has_key("PATH_INFO"):
+        func_path = _req.subprocess_env["PATH_INFO"][1:] # skip fist /
+        func_path = string.replace(func_path, "/", ".")
+        if func_path[-1] == ".":
+            func_path = func_path[:-1] 
 
-    # if any part of the path begins with "_", abort
-    if func_path[0] == '_' or string.count(func_path, "._"):
-        raise apache.SERVER_RETURN, apache.HTTP_NOT_FOUND
+        # if any part of the path begins with "_", abort
+        if func_path[0] == '_' or string.count(func_path, "._"):
+            raise apache.SERVER_RETURN, apache.HTTP_NOT_FOUND
+    else:
+        func_path = "handler"
 
     # process input, if any
     fs = util.FieldStorage(req, keep_blank_values=1)


More information about the Mod_python mailing list