Popen and Django Dev Server
May 13, 2011
I have code that does this:
lCommand = ["hg","history", "-r", "%s:%s" % (pFrom, pTo)] lProcess = subprocess.Popen(lCommand, stdin=subprocess.PIPE, stdout=subprocess.PIPE)
in a Django view. This is intended to get the mercurial history between two revision numbers so that it can be shown on a web page. When using the dev server, I'm quite often getting a blank page instead of my HTML, and for each page request the server outputs:
Django version 1.2.1, using settings 'dewsbury.settings' Development server is running athttp://127.0.0.1:8000/ Quit the server with CONTROL-C.
This is happening on every request. If I comment out the code that does the Popen, it works fine.
The Popen command is completing fine, I can print out the output on each request, it's just that the dev server is returning a blank page back to the browser. This is on the Django 1.2.1 release.
I've had a wander around the bugs related to this and the ones I could find seems to be closed as duplicate, or closed worksforme.
Solution
The solution was simple, but odd.
At the top of my code that runs Popen, I was doing this:
import subprocess import datetime import paramiko, base64, select, time import os
Changing this around so that os
was imported before subprocess
fixed the problem.