Skip to content

Commit d2f9413

Browse files
Baisangjeffwidman
authored andcommitted
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.
1 parent 70ea4c1 commit d2f9413

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

test/fixtures.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -296,10 +296,12 @@ def _create_zk_chroot(self):
296296
env = self.kafka_run_class_env()
297297
proc = subprocess.Popen(args, env=env, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
298298

299-
if proc.wait() != 0 or proc.returncode != 0:
299+
stdout, stderr = proc.communicate()
300+
301+
if proc.returncode != 0:
300302
self.out("Failed to create Zookeeper chroot node")
301-
self.out(proc.stdout.read())
302-
self.out(proc.stderr.read())
303+
self.out(stdout)
304+
self.out(stderr)
303305
raise RuntimeError("Failed to create Zookeeper chroot node")
304306
self.out("Kafka chroot created in Zookeeper!")
305307

@@ -458,13 +460,12 @@ def _create_topic(self, topic_name, num_partitions, replication_factor, timeout_
458460
args.append('--if-not-exists')
459461
env = self.kafka_run_class_env()
460462
proc = subprocess.Popen(args, env=env, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
461-
ret = proc.wait()
462-
if ret != 0 or proc.returncode != 0:
463-
output = proc.stdout.read()
464-
if not 'kafka.common.TopicExistsException' in output:
463+
stdout, stderr = proc.communicate()
464+
if proc.returncode != 0:
465+
if not 'kafka.common.TopicExistsException' in stdout:
465466
self.out("Failed to create topic %s" % (topic_name,))
466-
self.out(output)
467-
self.out(proc.stderr.read())
467+
self.out(stdout)
468+
self.out(stderr)
468469
raise RuntimeError("Failed to create topic %s" % (topic_name,))
469470

470471
def create_topics(self, topic_names, num_partitions=None, replication_factor=None):

0 commit comments

Comments
 (0)