On Sep 22, 2011, at 5:34 AM, babbu Pehlwan wrote: > I want to update logfile as soon as a request comes. I have a class > variable event_logging_enabled which is initialised to TRUE. and in > the POST() function I check the value of event_logging_enabled. > > Now at run time, I modify the value of this flag to FALSE for > subsequent requests. But It remains TRUE. > > During debugging, I found that when a request is received, a new > object get created to handle each request, so, will pick initialized > value i.e.TRUE. > > This is not the case for other functions like getlogEnabled() of same > class. > Can you please suggest any work around. > > import web > import threading > > class webServer(threading.Thread): > port = "1234" > event_logging_enabled = "True" > > def getlogEnabled(self): > print "Stub getlogEnabled(): ",self.event_logging_enabled > > def __init__(self): > threading.Thread.__init__(self) > """ Logging """ > print "Init------------------------",self.event_logging_enabled > self.event_logging_filename = "ueLogs.log" > > def run(self): > urls = ( > '/','webServer', > ) > app = web.application(urls,globals()) > sys.argv.append(webServer.port) > app.run() > > def POST(self): > print "in POST" > print "Stub POST(): Logging Enabled : > ",self.event_logging_enabled >
That's the nature of CGI web applications. When a request is recived a new instance of the application is created by the server. When the request has been processed, the application terminates. It looks like you are trying to track state between the initial web page and the post. Web browsers are inherently stateless. You need to do something so that the server can figure out the state. The simplest way would be to put a hidden field on the form and check that field during the post. The more infolved but standard way this is handled is using sessions. Look at webpy's session module. Mark -- You received this message because you are subscribed to the Google Groups "web.py" 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/webpy?hl=en.
