Life cycle of a mod_python application and scope of global variables

Kyle Yancey lakeofburningfire at kyle.orgdon'tspamme
Fri Jan 24 19:30:16 CET 2003

Correction.  The code should have been this.

#!/usr/bin/env python
from mod_python import apache

def handler(req):
   req.content_type = "text/plain" 
   i = i + 1
   return apache.OK

On Fri, 24 Jan 2003 18:13:49 GMT, Kyle Yancey
<lakeofburningfire at kyle.orgdon'tspamme> wrote:

>I've been trying out mod_python + apache + WinXP lately.  I was
>wondering if I could get some help clarifying a few things.
>My primary concern is with the lifespan of global variables.  As I
>understand it, in mod_python a global variable is initialized when the
>handler script is first started.  Global variables are not released
>when the instance of the script ceases, and the variable is
>essentially static and global for all instances of the handler script.
>#!/usr/bin/env python
>from mod_python import apache
>def handler(req):
>   req.content_type = "text/plain" 
>   req.send_http_header()
>   req.write(i)
>   return apache.OK
>Consecutive executions of this script will output
>Are global variables just shared between multiple threads, and should
>they be protected with mutexes to prevent race conditions.  I'm a bit
>confused about this since I'm just now learning about multithreading.
>I'm aware that the smart thing to do is to just not use them, but I
>hate being uncertain about what is going on.

More information about the Python-list mailing list