The anatomy of a hack to get around try:/finally: and generators

Suppose that you have the Python try:/finally: problem and need to get around it, specificallyyou need to both be a generator and have your finally: runimmediately. Taken from here ,one answer is:

def foo(bar):  try:    def output():      ... compute with bar ...        yield res      ...    return output()  finally:    print "finalizing"

(Now, there is a lot of things that this doesn't help with; the actualcomputation


When code in generators runs

Due to another entry I'm in the process of writing, I was suddenlystruck with a question: in Python, when does the code in a generatorfunction start running?

First, the brief version of generators and iterators. To handwavesomewhat, a generator is a function that uses yield to create andreturn its results one at a time. Behind the scenes, such a functionactually returns an iterator object, which the Python interpreter usesto freeze and unfreeze the actual code as the function's code calls


The usefulness of a syndication feed of your blog's comments

One of the accidental smart decisions that I made when I was writing DWiki 's code for syndication feeds was that I should create syndicationfeeds for comments as well as entries. (This built on an earlierdecision that I should have some way of getting a list of comments inchronological order, just as I had one for the standard wiki 'recentlyedited pages' feature.)

It isn't that I think this is an important feature to offer otherpeople; as far as I know, none of the


A peculiar change in Linux flock() and fcntl() behavior

Here is one of those fun issues that cause me to pull out my hair(although it can give me a peculiar sense of satisfaction to track itdown).

Suppose that you have two filenames, such as (not entirelyhypothetically) .vacation.dir and .vacation.pag . As it happens,these filenames are actually hardlinks, so there is only one actualfile involved. Now, suppose you have code that is like this C-oidpseudo-code:

fl = {F_WRLCK, SEEK

Thinking like a security paranoid: an example

There's been a bunch of commotion lately over OpenSSH and how perhapsthere's a 0-day exploit in an older version of it, and so on. Giventhis, clearly the thing to do is upgrade to a current version justin case, right?

If you think this, you're not thinking like a security paranoid.Allow me to illustrate.

Imagine that you are an attacker. You've found a vulnerability inthe very latest and most recent version of OpenSSH, and you want


Packages should not contain both tools and policies

If you install the Ubuntu mdadm package on a machine with nosoftware RAID arrays, it will 'helpfully' email you every dayto report:

checkarray: W: no active MD arrays found.
checkarray: W: (maybe uninstall the mdadm package?)

(The message comes from the /usr/share/mdadm/checkarray shell script.)

This is a terrible idea , forreasons beyond that it's not an error. (It might be an error if thescript bothered to check to see if


Minimalistic spam, another annoyance to worry about

I've started getting advance fee fraud spam which have as their entirecontents something like this:

You won Three Million Pounds.contact Anita Meyer :

At first I was amused by the minimalism and lack of effort on thespammer's part; it'd be hard to get an advance fee fraud attempt in lesswords. But the more I think about it, the more that I think this may bemore clever than it looks (whether or not it's deliberate).


The importance of making an issue visible

One of the things that's started to help the program energy efficiencyissue on Linux is the developmentand popularization of programs like iotop and powertop . For thefirst time, people could conveniently get a simple overview of what wasgoing on with IO and power on their system and, not surprisingly, peoplereacted to what they saw.

This provides a handy illustration of the importance of making anissue or a behavior visible to people, both to users and especially toprogrammers. By and large, if things run well


Why NFS filehandles fail as access capabilities

I think it's clear that Sun initially intended NFS filehandles to serve as capabilities , ieopaque tokens that could be used to grant access to useful thingslike your files. Unfortunately, pretty soon it was clear that this didn't work and NFS filehandlesactually made pretty terrible access capabilities.

(I may be mis-using the term 'access capabilities' here. As I learnedit, it refers to opaque (to the user) tokens or identifiers that youcan present to services to get access to some


The hard problem of live major release upgrades

I've held forth before on things that boil downto 'it would be really nice if my favorite Linux distribution had liverelease upgrades'.

One might think that this is an easy feature to add. After all, in amodern Linux an upgrade from one release to the next mostly consistsof updating a huge number of packages, and everyone has excellent,very well tested support for doing that. So, just change things to getpackages from the new release's repository and do a regular packageupdate