diff --git a/debian/changelog b/debian/changelog
index 115ea505d58afa22a61c8b8d061fc36e46e3ac42..23578eea15e4d87230a947965df23c47c936bdde 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,3 +1,10 @@
+python-defaults (2.6.5-9) UNRELEASED; urgency=low
+
+  * pyclean, pycompile: use .communicate() instead of .wait() to avoid hanging
+    `dpkg -L PACKAGE` in few situations
+
+ -- Piotr Ożarowski <piotr@debian.org>  Sat, 17 Jul 2010 18:58:23 +0200
+
 python-defaults (2.6.5-8) unstable; urgency=low
 
   * Revert:
diff --git a/pyclean b/pyclean
index b3fe7383792c35cb799689df9b6c7c7243d9f234..c13fcb1ff648330d28a7ff0267e5c572e166f801 100755
--- a/pyclean
+++ b/pyclean
@@ -85,12 +85,13 @@ def get_files(items):
 
 
 def get_package_files(package_name):
-    process = Popen("/usr/bin/dpkg -L %s" % package_name, shell=True, \
-                    stdout=PIPE, stderr=PIPE)
-    if process.wait() != 0:
+    process = Popen("/usr/bin/dpkg -L %s" % package_name,\
+                    shell=True, stdout=PIPE)
+    stdout, stderr = process.communicate()
+    if process.returncode != 0:
         log.error('cannot get content of %s', package_name)
         sys.exit(2)
-    for line in process.stdout:
+    for line in stdout:
         line = line.strip('\n')
         if line.endswith('.py'):
             yield line
diff --git a/pycompile b/pycompile
index 249ce5f06dfde7cc59dbda16f358593ede08e65c..ba618cf1ef59c15cb2431e5dd2487bea384f0d6e 100755
--- a/pycompile
+++ b/pycompile
@@ -68,12 +68,13 @@ def get_directory_files(dname):
 
 def get_package_files(package_name):
     """Generate *.py file names available in given package."""
-    process = Popen("/usr/bin/dpkg -L %s" % package_name, shell=True, \
-                    stdout=PIPE, stderr=PIPE)
-    if process.wait() != 0:
+    process = Popen("/usr/bin/dpkg -L %s" % package_name,\
+                    shell=True, stdout=PIPE)
+    stdout, stderr = process.communicate()
+    if process.returncode != 0:
         log.error('cannot get content of %s', package_name)
         exit(2)
-    for line in process.stdout:
+    for line in stdout:
         line = line.strip('\n')
         if line.endswith('.py'):
             yield line