Pages

Monday, July 10, 2017

Django trick keep runserver from crashing on Python syntax error

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 apps source code.  We can have a rapid "edit stuff then see what happened" cycle.

However, runserver it has an annoying habit. If were 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 doesnt 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

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.