TurnKey Linux Virtual Appliance Library

Unix buffering delays output to stdout, ruins your day

Let's say you have the following program:

cat>example.py<<'EOF'
#!/usr/bin/python
import time
while True:
    print 'hello world'
    time.sleep(1)
EOF

chmod +x ./example.py

If you run this program from a terminal, it will print hello world every second.

But redirect the output to a file and something different happens:

./example.py > output &
tail -f output

You won't see any output! (At least not for a long while)

Two simple ways a script can detect if it's online

I didn't want installation of one of TurnKey's components to freeze up too long if it was installed offline so I looked for a nice way to detect that without bringing in additional dependencies.

Two methods stood out...

  1. ping Google DNS servers: one second constant delay, regardless if you're online or off:

configuring libresolv to timeout DNS queries to unreachable nameservers more quickly when offline

When I go offline I pull my network cable. This causes DNS queries to take forever to resolve. Actually 40 seconds but it feels like forever.

StdTrap: a magical Pythonic mechanism for intercepting console output

As a programmer I believe less is more. Good code is small, simple and elegant and many times favorable to larger, noisier code that does the same. It's not just about aesthetics either. Making code small and beautiful makes it easier to read, and easier to understand. Which is guaranteed to make it work better. Trust me on this.

How Foodsoft inspired me to rewrite the TKLDev documentation

A couple of weeks ago I was corresponding with @wvengen, a free software developer from the Netherlands who has been using TKLDev to package Foodsoft into a ready-to-use Foodsoft in a box solution that can be easily deployed to manage your own non-profit Food Coop.

TurnKey 13.0 ready for community development

Want to roll your own Debian Wheezy based images? You're in luck because we just finished upgrading TurnKey's build chain, including new versions of TKLDev and TurnKey Core ready for download.

Using Comet to update web application data in real time?

Recently I've been looking into a powerful but complex web application technology we're considering using in future versions of the Hub.

The problem: how do we update a browser view when a background process updates the database?

A few examples of places in the Hub where this comes up...

Python iterators considered harmful

I just tracked down a nasty bug in my code to a gotcha with Python iterators.

Consider the following code...

How to write a good changelog

In a nutshell, think of your users.

They read top to bottom. They have a very limited attention span. Even if they read all the way through, they're probably going to pay more attention to things that come early. Before patience runs thin.

So your goal is not only to describe changes but to figure out now to communicate as much value to users before they lose interest. If you do a really good job, you might actually prevent them from losing interest and they'll read all the way through. Don't bet on it though...

Python property gotcha

If you like using a single getter/setter function for your properties, watch out if using None for the default. If you do that you won't be able to set your property to None!

Example code and workaround...