Hi all,
I have come across a strange problem when I configured my web.py code
with Apache.
I have 3 variable which I need to use across 2 classes. I used to
handle this using *global variables* but unfortunately that doesn't work
now.
Example:
#################
urls = (
'/', 'index',
'/result','Result'
)
class index:
def POST(self):
global VAR1, VAR2, VAR3
i = web.input()
VAR1 = i.word1.__str__()
VAR2 = i.word2.__str__()
VAR3 = i.word3.__str__()
raise web.seeother('/result')
class Result:
def GET(self):
*print VAR1, VAR2*
return r_result(VAR1, VAR2)
def POST(self):
print VAR2, VAR3
This works perfectly fine when I run the code independently, but when used
in the apache settings it gives:
*NameError: global name 'VAR1' is not defined* at the print statement in
Result.Get
I was checking the ApplicationIssues:
http://code.google.com/p/modwsgi/wiki/ApplicationIssues and found out
following statement.
#######################
*Application Global Variables*
Because the Python sub interpreter which hosts a WSGI application is
retained in memory between requests, any global data is effectively
persistent and can be used to carry state forward from one request to the
next. On UNIX systems however, Apache will normally use multiple processes
to handle requests and each such process will have its own global data.
This means that although global data can be used, it can only be used to
cache data which can be safely reused within the context of that single
process. You cannot use global data as a means of holding information that
must be visible to any request handler no matter which process it runs in.
#######################
I have to pass those variables across the functions. I also tried appending
the variables to *__builtin__* but it didn't workout either.
I hope I made myself clear.
Can someone help me regarding this?
Thanks & Regards
Avinesh
--
You received this message because you are subscribed to the Google Groups
"web.py" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/webpy?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.