Python deadlocks when Popen in multithread.

INADA Naoki songofacandy at gmail.com
Mon Oct 11 16:19:30 EDT 2010


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

#http://codepad.org/GkoXHbik

#!/usr/bin/env python

from subprocess import *
from threading import *

THREAD_COUNT=50

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