On 9 April 2012 21:03, Joonas Lehtolahti <[email protected]> wrote:
> On Mon, 09 Apr 2012 13:49:05 +0300, k4ml <[email protected]> wrote:
>
>> 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
>
>
>
>> from php import PHPApplication
>>
>> php = PHPApplication()
>> php.printx("hello world")
>>
>> application = php
>>
>> 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 ?
>
>
> The only place where you do increase counter is in __init__ and you do it
> only right after setting counter to 0. So counter will always be 1, no
> matter what. Perhaps you should move self.counter += 1 to __call__ method?
Which will not help unless also move:
self.out = []
self.out.append(str(self.counter))
to the __call__ method.
Having:
php.printx("hello world")
at module scope is also wrong.
The basic misunderstanding here is probably the belief that the whole
contents of the file are executed on each script when they aren't.
The script is only loaded once for the life of the process and then on
each request the application callable is called. In this case the
__call__() method.
Graham
--
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.