waylan wrote: > Gleb Rybkin wrote: > >>when running apache, mod_python in windows. >> >>This looks pretty strange. Creating a simple python file that shows >>current time will correctly display the time in apache the first time, >>but freezes afterwards and shows the same time on all subsequent clicks >>as long as the file is not modified. >> >>Any ideas what's wrong? Thanks. > > > The first time the page was requested mod_python compiled and loaded > your code. Every request after that mod_python refers to the already > loaded code in memory in which your expression had already been > evaluated the first time. > > Therefore, you need to make curtime a 'callable object' so that it will > be re-evaluated on each request. Unfortunelty, I don't recall if simply > wraping your strftime() expression in a function will be enough or if > its more complex that that. That said, I **think** this should work: > >>from mod_python import apache >>from time import strftime, gmtime >> > > def curtime(): > return strftime("%a, %d %b %Y %H:%M:%S +0000", gmtime()) > > >>def handler(req): >> req.content_type = "text/plain" >> req.send_http_header() >> req.write(str(curtime())) >> return apache.OK > > This is a very long way round for a shortcut (though it does have the merit of working). Why not just
def handler(req): req.content_type = "text/plain" req.send_http_header() curtime = strftime("%a, %d %b %Y %H:%M:%S +0000", gmtime()) req.write(str(curtime)) return apache.OK Or even def handler(req): req.content_type = "text/plain" req.send_http_header() req.write(strftime("%a, %d %b %Y %H:%M:%S +0000", gmtime())) return apache.OK regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC/Ltd http://www.holdenweb.com Skype: holdenweb http://holdenweb.blogspot.com Recent Ramblings http://del.icio.us/steve.holden -- http://mail.python.org/mailman/listinfo/python-list