[mod_python] Persistent variable again...

Gregory (Grisha) Trubetskoy grisha at modpython.org
Tue Apr 17 10:00:47 EST 2001


I think you have a bug because you have "count" and "counter", so it may
not work for this reason alone.

But also - if this is on UNIX, then you have to keep in mind that Apache
runs as several independent processes, and you can only have persistance
per-process. There is no "simple" way to have cross-process persistance.

On Win32, where Apache runs as a single process, it should work OK.

Grisha

On Tue, 17 Apr 2001 nineclue at bigfoot.com wrote:

> Greetings...
>
> I've posted somewhat long python program during development, which
> may need pg module, postgres running with pyweb db created etc...
>
> Here's short version, which don't work as I expected.
>
> from mod_python import apache
>
> session_data = {}
> session_counter = 0
>
> def handler(req):
>         global session_data, session_counter
>
>         if session_data.has_key('counter'):
>                 session_data['count'] = session_data['count'] + 1
>         else:
>                 session_data['count'] = 0
>
>         session_counter += 1
>         req.write('<HTML>')
>         req.write('Session data has %d items<BR>' % len(session_data))
>         req.write('Counter : %02d<BR>' % session_data['count'])
>         req.write('Alternative Counter : %02d<BR>' % session_counter)
>         req.write('</HTML>')
>         return apache.OK
>
> When I loaded the page and tried several reloads, session_data dictionary
> variable is never increased and session_counter variable is increased
> after several tries. What I expected was both variable increase at each
> reload.
>
> In my thoughts, dictionary variable is not supported and main interpreter
> is created in each Apache processes, which is shared by subinterpreters.
>
> Sorry for posting again, long message and my poor English.
>
> Thanks in advance.
>
> _______________________________________________
> Mod_python mailing list
> Mod_python at modpython.org
> http://www.modpython.org/mailman/listinfo/mod_python
>




More information about the Mod_python mailing list