Wildflowers galore!

Wildflowers galore on the way up to Mt Outram. Best viewed from the trail, of course.

As we plodded our way up the steep trail to Mt Outram, we met a hiker on her descent who exclaimed that the flower display awaiting us was possibly the best she’d ever seen. When we broke out of the trees onto the open slopes, we could barely believe our eyes. The meadows were absolutely filled with all manner of flowers; the blues, reds, and yellows of lupine, paintbrush, and arnica making for a truly eye-catching view. I think every colour of the rainbow was well represented.

It’s always a little difficult to capture such rich displays. Either the flowers end up looking like little dots, and there’s nothing to draw you into the photo, or a small number of flowers becomes the focus, and some of the grandeur and extent of the meadows is lost. But this one seems to strike the right balance, especially with the distant mountains lending a bit of depth and providing a level horizon to emphasize the steep slope.

Unbuffered output to stdout from Python programs

I recently had cause to debug a Python program that extracts data from a remote (MySQL) database and stores in a local SQLite database. I did the usual thing of inserting print statements to check a handful of variables at different stages of the process, but it wasn’t helping because the program would stay obstinately quiet until the end and then print all the information at once.

Wait, but why? Then I remembered that the info being written to stdout was buffered, so that I was only seeing the messages once the buffer had been filled. That’s all well and good, and perfectly efficient and all, but it was getting in the way of my debugging.

The solution I found was to configure stdout in the Python code to be unbuffered. Thanks to this helpful blog entry at Turnkey Linux, I added the following line to the start of my program (plus the required imports):

sys.stdout = os.fdopen(sys.stdout.fileno(), 'w', 0)

Bingo! No more waiting for my print statements to show up. Cue happy dance. Now I can get on with solving the actual problem I’m having with the code…

(I tried the other solution mentioned, stdbuf, but either I was using it wrong, or it wasn’t doing what I expected it do to.)