How not to copy a file to standard output in Python

Suppose that you are quickly bashing together a CGI that as part ofits job has to spit out a file. When I needed to do this recently, Ireflexively wrote more or less:

fp = open(fname, "r")for line in fp:    print line

(Because this was reading from a file, my usual objections to using file iteration don't apply.)

Somewhat later I got a politely phrased report from the person that thiswas for to the effect that the PDFs this CGI was


My views on inheritance versus interface

Due to some recent entries , I've been thinking more about inheritanceand interfaces and I've come around to a particular view, which youcould call either the duck typing view or the jaundiced C programmer'sview. Put simply:

Interfaces are what you should care about from outside amodule. Inheritance is, or should be, strictly an implementationissue for inside the module, except when inheritance is the simplestway to expose certain functionality for reuse by the outsideworld.

(In Python, Exception is


Why I am not enthused about etckeeper and similar systems

There are a number of programs like etckeeper , systems for keepingyour /etc and similar things in various forms of version controlsystem repositories. I'm not enthused about any of them as comparedto, say, keeping selected files in /etc in RCS ,because I see several problems with them.

First off, you're fighting with your regular package management system;both it and your etckeeper system feel that they own files in /etc andcan change them. Even if you try to integrate the two


Why whitelists (and blacklists) are long-term poison for online systems

Every so often, well intentioned people propose that we can dealwith the problems of various sorts of abuse in online forums and systemsby having people build whitelists or blacklists (often with some sort ofautomated web of trust system). While this sounds great, it's a bad idea.

One of the old lessons from Usenet is that resorting to individualwhitelists or blacklists to make a forum usable is ultimatelydestructive to the forum itself, because it more or less totally killsoff the supply of good newcomers to the


Overcoming the drawbacks of preforking accept() servers

I was going to say that while preforking accept() -based servers don't in practice have a thundering herdproblem, they do have two other issues, namely there's no way to tellwhen you need to grow the number of processes you're using and no way totell if a process has frozen. (The more complicated preforking scheme has neither problem.)

However, some thought showed me that it's possible to get around theseproblems while retaining the advantages of the pure accept(


What version of Python is included in various current OSes

For my own curiosity, here is a rundown of what version of Python is invarious current OS distributions, along with whether or not a version ofPython 3 is available as an optional package.

(The version of Python is my best guess at what you get if you runplain ' python ' at a command line.)

OS Python version Optional Python 3?
Solaris 10 update 82.4.4 (2.6 available in Blastwave)No
Red Hat Enterprise 5
(and CentOS 5)
2

Learning from Unicorn: the accept() thundering herd non-problem

For a long time, one of my acquired articles of faith has been thatyou needed to worry about and avoid the thundering herd accept() problem. (This is the problem where ifyou have a bunch of processes all waiting in accept() and a singleconnection comes in, many kernels will wake all of the processes up onlyto have most of them immediately go back to sleep.)

One of the things that Unicorn (via Ryan Tomayko and others )has taught me about preforking servers is that the


The problem with the OpenSolaris source repository

It's nice that Sun has provided the OpenSolarissource in the form of a VCS repository , but inmany ways it's not terribly useful. The problem with it is that theOpenSolaris repo is not a working repository.

By that I mean that it is not what the Sun developers actually workin; instead it is essentially a series of code snapshots convertedto a repository. It's nice that we get a sequence of snapshots ina convenient form, and it's nice that it happens relatively


The mixed directory/unrelated files VCS problem

To follow up an earlier entry , one might sensibly askwhat the problem is with using a modern, whole-directory version controlsystem on a directory full of unrelated files, the classical examplebeing /etc .

What you effectively have in this situation is a directory with multiple'modules' (files and groups of files) that are logically separate andindependent from each other. As they're separate modules, these filesusually evolve and are developed at least somewhat independently.Putting all of these files into a single


Poking around the OpenSolaris codebase (for sysadmins)

If you do much work with Solaris things like DTrace and mdb -k , youare sooner or later going to want to poke around the OpenSolaris code,both for kernels and for utilities and so on. If you do this very much,you are going to want your own local copy of the OpenSolaris codebase(while you can use the OpenSolaris website, sooner or later navigatingthrough it will drive you mad). You can get a copy with Mercurial; see here for instructions onhow. For spelunking purposes,