ensure the pipe is closed when we are done with the subprocess
[auto-debuild.git] / auto_debuild.py
index a7087985b285161ee58fa607045526e3aad0cde5..bee82caa859df4fc1759e937bc038a1a4fb8136b 100755 (executable)
@@ -177,9 +177,9 @@ def commandInBuildEnv(config, command):
 
 def getArchitecture(config):
        cmd = commandInBuildEnv(config, ['dpkg-architecture', '-qDEB_HOST_ARCH'])
 
 def getArchitecture(config):
        cmd = commandInBuildEnv(config, ['dpkg-architecture', '-qDEB_HOST_ARCH'])
-       p = subprocess.Popen(cmd, stdout=subprocess.PIPE)
-       res = p.communicate()[0] # get only stdout
-       if p.returncode != 0: raise Exception("Querying dpkg for the architecture failed")
+       with subprocess.Popen(cmd, stdout=subprocess.PIPE) as p:
+               res = p.communicate()[0] # get only stdout
+               if p.returncode != 0: raise Exception("Querying dpkg for the architecture failed")
        return res[0:len(res)-1] # chop of the \n at the end
 
 def writeDependency(f, name, list):
        return res[0:len(res)-1] # chop of the \n at the end
 
 def writeDependency(f, name, list):