I was toying around with simple wsgi application (I just learnt about
mod_wsgi AddHandler directive, for so long I have been using
WSGIScriptAlias to launch my wsgi app). So the idea is to have
something that closely resemble PHP way of executing the application.
Don't ask me why, just for fun. I use Django or Flask for real thing.

So here's my application defined in ../app/php.py:-


class PHPApplication(object):
    def __init__(self):
        self.out = []
        self.counter = 0
        self.counter += 1
        self.out.append(str(self.counter))

    def printx(self, out):
        self.out.append(out)

    def __call__(self, environ, start_response):
        start_response('200 OK', [('Content-type', 'text/html')])
        for out in self.out:
            yield out


and the index.py:-


import os
import sys

CUR_DIR = os.path.abspath(os.path.dirname(__file__))
LIB_DIR = os.path.abspath(os.path.join(CUR_DIR, '../lib'))
APP_DIR = os.path.abspath(os.path.join(CUR_DIR, '../app'))

for path in (LIB_DIR, APP_DIR,):
    if path not in sys.path:
        sys.path.insert(0, path)

from php import PHPApplication

php = PHPApplication()
php.printx("hello world")

application = php

and the apache vhost config:-

DocumentRoot /home/kamal/pylikephp/htdocs
DirectoryIndex index.py

Options ExecCGI

AddHandler wsgi-script .py

Order allow,deny
Allow from all


WSGIDaemonProcess pylikephp processes=1 threads=2 display-name=%
{GROUP}
WSGIProcessGroup pylikephp

My initial thought was the counter will always get incremented since
the application object was created only once during mod_wsgi daemon
process initialization. But it look like the application object is
created on each requests since the counter always stayed at 1 even
after refreshing my browser few times. What I'm missing here ?

If this is how mod_wsgi work, does it safe to build my application
like this - allow user to initialized my Application, call some method
on it and be sure that the application is destroyed when the request
end ?

-- 
You received this message because you are subscribed to the Google Groups 
"modwsgi" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/modwsgi?hl=en.

Reply via email to