Monday, May 30, 2016

Django trick: keep "runserver" from crashing on Python syntax error

When developing Django, the "runserver" command is convenient. It runs our appserver, and reloads itself when we change our app's source code.  We can have a rapid "edit stuff then see what happened" cycle.

However, runserver it has an annoying habit. If we're typing so fast that we add a Python syntax error into our code, the  command will crash. We expect that when we fix the syntax error, we can see our results, but it doesn't work. The appserver has crashed, and is no more.
 

The following workaround works wonders. If we add a syntax error, "runserver" will crash, and this loop will wait for a moment then re-run it. We can now type as fast as possible all the time, and Django will always show us what we want to see. Or, what we give it, which sometimes is enough ;)



while true; do ./manage.py runserver; sleep 15; done

Creativity

In my creative and job work, I've learned how to move around and have great ideas.

It turns out these things are related.

In "Doodle Revolution", Sunni Brown points out that moving and creative thinking are related.  Steve Jobs would go on "power walks" not to clear his mind but to focus and to work through creative blocks.  Einstein would play the violin, improvising melodies while pondering complicated problems. Tesla could design and run machines in his mind, not bothering to draw them out!

At work I walk around as much as possible. Often I'll jog around the block to stimulate the little gray cells. Before or after lunch I'll draw my coworkers or tourists or cute dogs. At meetings and when learning new material I'll take notes on paper, adding lines and diagrams and fonts as much as possible. It's fun, and it helps me concentrate on the material, and integrate into my brain.

I recommend everyone go out at buy Brown's book, or at least watch her TED talk "Doodlers, unite!" She's on the twitters at @SunniBrown 

Here's my notes from 2015's Continuous Delivery "cdSummit SoCal" conference