Why does this hang sometimes?

Jesse Jaggars jhjaggars at gmail.com
Thu Apr 12 17:25:47 EDT 2012


Possibly. I wonder what the difference(s) is(are)?

On Sat, Apr 7, 2012 at 5:54 PM, Jason Friedman <jason at powerpull.net> wrote:
>> 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
>
> I can confirm hanging on my installation of 2.7.2.  I also ran this
> code 100 times on 3.2.2 without experiencing a hang.  Is version 3.x a
> possibility for you?



More information about the Python-list mailing list