subprocess.Popen calling httpd reload never finishes

Nan ringemup at gmail.com
Tue Aug 17 15:55:21 EDT 2010


Hi folks --

I have a Python script running under Apache/mod_wsgi that needs to
reload Apache configs as part of its operation.  The script continues
to execute after the subprocess.Popen call.  The communicate() method
returns the correct text ("Reloading httpd: [  OK  ]"), and I get a
returncode of 0.  But the python script (Django) that calls Popen
never seems to complete (by returning an HTTP response.

Any other Popen call I've tried exits properly.  Here's some sample
code:

		args = ['sudo /etc/init.d/httpd reload']
		proc = subprocess.Popen(args, stdin=subprocess.PIPE,
stdout=subprocess.PIPE, stderr=subprocess.STDOUT, shell=True,
close_fds=True)
		(stdout_txt, stderr_txt) = proc.communicate("")
		proc.wait()
		logging.debug('%d %s<hr />%s' % (proc.returncode, stdout_txt,
stderr_txt))
		logging.debug('still executing')
		return HttpResponse('done')

The logging statements are output, but the script doesn't exit.  If
you substitute "sudo ls -l" or "sudo /etc/init.d/httpd configtest" for
"sudo /etc/init.d/httpd reload", the exits properly.

 Any idea what I might be doing wrong?

Thanks!



More information about the Python-list mailing list