Python deadlocks when Popen in multithread.

INADA Naoki songofacandy at
Mon Oct 11 22:19:30 CEST 2010

On Ubuntu 10.10 amd64 and dual-core CPU, following code deadlocks.
What's wrong on this code?


#!/usr/bin/env python

from subprocess import *
from threading import *


def worker():
    p = Popen(["cat"], stdin=PIPE, stdout=PIPE, stderr=STDOUT)
    out = p.communicate("hoge")[0]
    print "%s %s" % (current_thread().name, out)

threads = []
for i in range(THREAD_COUNT):
    threads.append(Thread(target=worker, name=str(i)))
for t in threads: t.start()
for t in threads: t.join()

More information about the Python-list mailing list