Why does this hang sometimes?

Jesse Jaggars jhjaggars at gmail.com
Wed Apr 4 17:09:50 EDT 2012


I am just playing around with threading and subprocess and found that
the following program will hang up and never terminate every now and
again.

import threading
import subprocess
import time

def targ():
   p = subprocess.Popen(["/bin/sleep", "2"])
   while p.poll() is None:
       time.sleep(1)

t1 = threading.Thread(target=targ)
t2 = threading.Thread(target=targ)
t1.start()
t2.start()

t1.join()
t2.join()


I found this bug, and while it sounds similar it seems that it was
closed during python 2.5 (I'm using 2.7.2):
http://bugs.python.org/issue1404925

Thanks!



More information about the Python-list mailing list