KBD

Keith Devens .com

Saturday, August 30, 2008 Flag waving
The direct pursuit of happiness is a recipe for an unhappy life. – Donald Campbell
← It's like beating your head against a wall...The Onion: Mom Finds Out About Blog →

Daily link icon Sunday, November 16, 2003

Leaving PHP for Python

Woo, I'm finally leaving PHP. I have my local mod_python environment set up the way I want it, Cheetah's installed and working, etc. The only thing is that now I have to learn a new environment. The Cheetah documentation isn't good enough, and I'm not sure how I'm supposed to develop with it. I don't think there's a method that will automatically cache a compiled version of a template, for example, so I think I have to do that stuff myself, which is at a lower level than I expected to have to go.

It's not a big deal, and until I'm ready for "production" I can just leave it compiling on the fly for now, but the main issue is that I don't yet have a feeling for how the developers expect you to use Cheetah with mod_python. For instance, most of their documentation is about using Cheetah from the command line (and they have a little bit about using it with Webware too).

The other big problem is that if I get any errors, they go to the Apache error log, even though I have "PythonDebug on" in my httpd.conf, which sucks.

Oh, as for templates, since global variables stay in memory between requests, I could always just leave all my templates sitting around in memory (I don't have that many templates that it would be a problem). However, the fact that everything stays in memory in the first place bothers me a bit. If you ever accidentally assign something to a global variable you might have something big sitting around in memory forever and not realize it. And AFAIK, there's nothing automatic I can use to refresh the global environment, so I may have to write some tools myself to clear things and make sure the GC picks them up.

One more concern is that if mod_python ever starts sucking, or if it just turns out not to be the right solution for me, and I want to switch to Python with FastCGI or SCGI or whatever, I'm slightly worried about how much code I'd have to rewrite. Probably not much... but the point is that I'm still a little concerned about the reliability of mod_python.

Update: Apache error log problem fixed. It seems that PythonDebug must be specified on the directory level. I had it in my httpd.conf, but not in a <Directory> block. I just stuck it in my .htaccess file and it worked fine.

← It's like beating your head against a wall...The Onion: Mom Finds Out About Blog →

Comments XML gif

Simon Willison (http://simon.incutio.com/) wrote:

I share your concerns about the portability of mod_python code to other environments, although our experience with mod_python here at work has been pretty reassuring so far in terms of reliability. That's why one of my main hopes for the Python Web-SIG is that it will help define a simple standard API which applications can be written against that will allow easy portability between mod_python, Twisted, CGI and so on. If you're interested in that kind of thing you should sign up for the mailing list.

∴ Simon Willison | 16-Nov-2003 4:29pm est | http://simon.incutio.com/ | #3287

Keith (http://keithdevens.com/) wrote:

Simon, any ideas on how to make sure your global environment is clean so you're not carrying around baggage in memory? Or, could you tell me how to make sure that errors go to the browser instead of the Apache error log? Do you know why they couldn't overload "print" to make it print to the request instead of having to call req.write() all the time?

Sorry for all the questions... thanks Smiley

Keith | 16-Nov-2003 4:51pm est | http://keithdevens.com/ | #3288

Simon Willison (http://simon.incutio.com/) wrote:

You can overload print yourself - just use "sys.stdout = req" at the start of your handler. As for the global environment, as long as you don't define any global variables you'll be fine and in Python globals are only created if you assign to something outside of a function or class. Actually this is pretty useful because it means you can do things like compiling regular expression objects just once for each Apache child.

Apache children are important to think about as well. mod_python actually creates a complete environment for every Apache child spun off by the Apache server. These children can be configured to have a lifetime of usually something like 5 minutes, after which the'll be killed and restarted (I forget what the default setting for this is). This means that any cunning plans involving caching stuff in global variables between requests will have to take in to account the fact that you'll have one cache per apache child, which can add up to a lot of memory if you aren't careful.

I'm not sure why your errors are going to the apache log - I've used PythonDebug on and had the errors appear in the browser window instead.

∴ Simon Willison | 16-Nov-2003 5:05pm est | http://simon.incutio.com/ | #3289

Keith (http://keithdevens.com/) wrote:

I'm not sure why your errors are going to the apache log

I guess PythonDebug has to be specified relative to a particular directory. I just had it in the global Apache config and it wasn't working, but if I'd had it in a <Directory> block it probably would have worked. I stuck it in my .htaccess and it worked.

Apache children are important to think about as well

Yikes, thanks. I thought it was only Python sub-interpreters I had to worry about.

Keith | 16-Nov-2003 9:21pm est | http://keithdevens.com/ | #3292

Jason wrote:

Good info thanks

∴ Jason | 19-Nov-2003 6:17pm est | #3314

Feel free to post a comment below. Please see my comment policy.

Formatting Rules (No HTML):

  • **bold**, *italic*, _underlined_, --strikeout--
  • "text"="url" creates a link, and URLs are auto-highlighted
  • Blockquote: Like e-mail, begin paragraph with > (greater-than sign)
  • Lists: begin paragraph with *,-, or + (unordered), or # (ordered)
  • Code block: ?!code:language=perl|php|sql|javascript|etc.{\n}...{\n}?!/code

:
(will be your IP address if blank)
: (optional)
(Will not be shown on site)

: (optional)
:

August 2008
SunMonTueWedThuFriSat
 12
3456789
10111213141516
17181920212223
24252627282930
31 



RSS feed RSS feed for Keith's Weblog
Atom feed Atom feed for Keith's Weblog
Weblog archive
Recent comments
  on 2 posts

Recent comments XML

new⇒Girls, please don't get breast implants

http://when-3.ofawyib.net​http://girls-24.iniexka.net​http://swingers-4.emy...

Henry: Aug 30, 4:15am

new⇒Johnny Walker Blue Label

Wow, thanks for the scotch review​:D

Lagavulin and Laphroaig are​some of...

Keith: Aug 29, 3:35pm

Generated in about 0.157s.

(Used 8 db queries)

mobile phone