summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrian Sang <sang.bri@gmail.com>2019-01-04 22:16:28 -0800
committerJeff Widman <jeff@jeffwidman.com>2019-01-05 14:38:53 -0800
commitd2f9413b0311e6ec4d782cf9983f61c9f258cc7b (patch)
treed7c6c098324d02203ebdeea5657b984d70e9a4e9
parent70ea4c1e94a0ace46d3418fb0ee503bbf8a5b91b (diff)
downloadkafka-python-d2f9413b0311e6ec4d782cf9983f61c9f258cc7b.tar.gz
Use Popen.communicate() instead of Popen.wait()
Popen objects may deadlock when using stdout=PIPE or stderr=PIPE with Popen.wait(). Using Popen.communicate() avoids the issue.
-rw-r--r--test/fixtures.py19
1 files changed, 10 insertions, 9 deletions
diff --git a/test/fixtures.py b/test/fixtures.py
index 6f7fc3f..34373e6 100644
--- a/test/fixtures.py
+++ b/test/fixtures.py
@@ -296,10 +296,12 @@ class KafkaFixture(Fixture):
env = self.kafka_run_class_env()
proc = subprocess.Popen(args, env=env, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
- if proc.wait() != 0 or proc.returncode != 0:
+ stdout, stderr = proc.communicate()
+
+ if proc.returncode != 0:
self.out("Failed to create Zookeeper chroot node")
- self.out(proc.stdout.read())
- self.out(proc.stderr.read())
+ self.out(stdout)
+ self.out(stderr)
raise RuntimeError("Failed to create Zookeeper chroot node")
self.out("Kafka chroot created in Zookeeper!")
@@ -458,13 +460,12 @@ class KafkaFixture(Fixture):
args.append('--if-not-exists')
env = self.kafka_run_class_env()
proc = subprocess.Popen(args, env=env, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
- ret = proc.wait()
- if ret != 0 or proc.returncode != 0:
- output = proc.stdout.read()
- if not 'kafka.common.TopicExistsException' in output:
+ stdout, stderr = proc.communicate()
+ if proc.returncode != 0:
+ if not 'kafka.common.TopicExistsException' in stdout:
self.out("Failed to create topic %s" % (topic_name,))
- self.out(output)
- self.out(proc.stderr.read())
+ self.out(stdout)
+ self.out(stderr)
raise RuntimeError("Failed to create topic %s" % (topic_name,))
def create_topics(self, topic_names, num_partitions=None, replication_factor=None):