« | » Main « | »

Grandma O, world traveller

Monday 30 May 2011

Last Friday would have been my Grandma O's 100th birthday, and just by luck my mother was in town, so we decided to celebrate by making a cake in Grandma's honor.

My grandmother traveled the world, and even when her mobility was limited, she made the most of what she could do, getting around New York City with a walker. So we pictured her with her tennis-ball-footed walker, circling the globe, tour bus at the ready:

Grandma O circling the globe

The tennis balls are fragments of marhsmallow dipped in yellow food coloring, the bus is a Twinkie. The blue of the ocean was supposed to be bluer, but a mis-capped green food coloring bottle was used before the mistake was noticed, and so the frosting is too green. We painted a little blue directly onto it to help pull it back to the right color without using too much bitter coloring.

The wire walker is a clear violation of our self-imposed rule that everything on the cake be either edible or Lego, but it was too central to the idea to omit it, and besides, if we couldn't bend the rules for Grandma O, epic rule-bender, who could we for?

The evening remembering Grandma O was fun, with stories of idealistic socialist Soviet-admirers from her generation and above, shaking our heads at how political fortunes have changed, and perspectives with them.

Teaching (and learning) Python

Sunday 29 May 2011

I taught David Beazley's 3-day Intro to Python class in Austin last week, and I really enjoyed it. I've always liked speaking in front of people (well, after the very first time, which was terrifying), and three days with a group of 15 made for a good intimate dynamic.

Interestingly, I learned a few tidbits about Python along the way:

  • The builtin enumerate() function has a two-argument form so that you can specify the first numbering value: enumerate(seq, start), handy for numbering lines in files, which should of course start with 1, not 0.
  • The -i switch to the Python interpreter will run your program, then leave you in the command prompt when it ends. This can be good for interactively testing the functions defined in the file, or for debugging if an exception happens.
  • If you use "python -i" and need to debug, pdb.pm() is the thing to use. It places you at the point where the last traceback was raised. It seems like magic, since the exception has already risen to the top level of the program, but pdb.pm() puts you "back in time" before the exception started its climb up through the stack.
  • 4 + True == 5. Useless, but there it is.

I liked explaining Python's elegant power, and it's fun to show experienced C programmers a different way of looking at programming. Trying to fit all the material into three days is a challenge, and there are interesting side-topics that I know we can't get into, which is a shame, but there's only so much you can do in a given amount of time.

Austin was a really fun city to explore on my own, too. If I had been more confident that I'd have energy left at the end of the day, I'd have tried to arrange some social events with other Python peeps. But the "Keep Austin Weird" vibe made it easy to wander around and find food trucks to eat at. My first night, driving down East 6th street, I saw a cluster of closed food trucks, with just one open, lit like a beacon at the back:

Pig Vicious

How could I not eat at a tiny truck named Pig Vicious manned by a giant tattooed bearded cook?

Running a database from a ramdisk

Thursday 12 May 2011

One project I'm working on these days is a large test suite for a Django project, in particular, trying to make it go faster. In one subset of 16 tests, total execution time is about 250 seconds! The tests clearly spend a lot of time in the database: 50% of the time is creating the test db, and another 30% is installing test fixtures.

A classic first step is to run the tests from an in-memory SQLite database. In this case, it's a Postgres database using GIS features, so changing engines isn't a simple settings change. Postgres doesn't have an in-memory feature, but I thought, why not force the database into memory without Postgres knowing, simply by creating the database in a ramdisk?

On Linux, this is a simple matter of creating the database in /dev/shm instead of a real disk-backed filesystem. And good thing it was simple, too, because it didn't help at all: the test times were completely indistinguishable between the two filesystems.

Which in retrospect makes perfect sense. Disk filesystems employ aggressive caching to keep data in memory in the first place, so it was unlikely that my simple trick was going to change things significantly. The test database is small enough to fit into RAM anyway, and for the tests, Postgres was already set to disable fsync.

The remaining mystery: why is SQLite in-memory faster than other databases on disk? If it is about the memory, then it should be possible to make other databases faster by forcing them into memory. And if isn't about the memory, then it's just that SQLite is faster no matter what (because it's in-process, for example) and using a disk-based SQLite should be faster than your real database also.

The Walk

Tuesday 10 May 2011

My son Nat is turning 22 this year, which means he leaves school, and his school residence, so we're working on finding a home for him. It's a complicated process, both logistically and emotionally. Nat needs supervision, and we're experts at it. It's hard to know how others will do looking out for him. His speech is idiosyncratic, he needs some help with daily tasks, and get fixated on unusual things.

The other day, Max handed me a small comic book and said, "read it, it's good." I assumed it was something funny, or Japanese, or otherwise appealing to a 19-year-old. But it wasn't, it was The Walk, by Ryan Pequin:

First panel of The Walk

I was stunned by this story. Russ is much older than Nat, but otherwise eerily similar to him. Nat could have said or done any of the things that Russ did in the story, except that he wouldn't go out by himself. Looking at how Russ experiences his life is very moving, and was the center of a number of conversations around our dinner table. Is Russ happy? Is he being well-cared for?

It's very hard to imagine what Nat's life will be like, there are so many unknowns. We want him to have as full a world as possible, but we also know that it's very intensive to provide him with opportunities and to make him successful at them. How do we find people that can give him what we can give him? How do we teach them all about Nat? How will we know what's really happening with him?

This story gently touches on all of these issues, with a character that could have been based on Nat. His window even looks like Nat's window in his school residence. I don't know what Ryan based the story on. The paper copy we have ends with "For Tom," and I don't know who Tom is. But Ryan has hit the nail on the head with The Walk.

Microbe cake

Thursday 5 May 2011

Max's girlfriend Hannah is studying microbiology, and her birthday is tomorrow, so tonight: a microbe cake! The cannon-like thing to the left is meant to be a microscope, but there's only so much you can do with Yodels and chocolate bars:

Microbe cake

How settrace really works, or doesn't

Wednesday 4 May 2011

It all started innocently enough, as it always does. A coverage.py bug said that the coverage trace function wasn't properly re-installed if this apparently innocuous line was executed:

sys.settrace(sys.gettrace())

I knew enough about trace functions to see that it was not going to be trivial to fix, but I didn't know how involved it was going to get. I certainly didn't expect that it would include finding a 10-year-old bug in Python itself!

Read all the details in How C trace functions really work.

I hope it's helpful or at least interesting. I don't know how many people are trying to write C trace functions, or care if they round-trip properly. Coverage.py's function works well now, and in a few years when I'm baffled by this again, I'll be able to come back and read it to remind myself of the details at least.

« | » Main « | »