[pypy-issue] [issue1283] A waiting stdin.read() in a thread + stdin.close() in another thread = the latter freezes
Jan Kaliszewski
tracker at bugs.pypy.org
Tue Oct 9 13:52:16 CEST 2012
New submission from Jan Kaliszewski <zuo at chopin.edu.pl>:
I encountered this behaviour when tried using multiprocessing.Process() when there was
a waiting stdin.read() in some thread.
A simple example -- which worked well under CPython 2.7, but freezes under PyPy 1.9 --
follows:
from multiprocessing import Process
from threading import Thread
import sys
def f():
while True:
sys.stdin.read()
def g():
print 'Process ok'
t = Thread(target=f)
t.daemon = True
t.start()
p = Process(target=g)
p.start()
p.join()
The problem is caused by sys.stdint.close() in multiprocessing.Process._bootstrap
(file 'lib-python/2.7/multiprocessing/process.py, line #249).
But then I realized that it is not multiprocessing/fork-specific issue.
Simply any waiting stdin.read() + stdin.close() in another thread causes that thread
to freeze (under PyPy, not under CPython), e.g.:
import sys
from threading import Thread
def f():
while True:
try:
sys.stdin.read()
except:
return
def f2():
sys.stdin.close()
print 'All right'
t = Thread(target=f)
t.daemon = True
t.start()
t2 = Thread(target=f2)
t2.start()
t2.join()
----------
messages: 4832
nosy: pypy-issue, zuo
priority: bug
release: 1.9
status: unread
title: A waiting stdin.read() in a thread + stdin.close() in another thread = the latter freezes
________________________________________
PyPy bug tracker <tracker at bugs.pypy.org>
<https://bugs.pypy.org/issue1283>
________________________________________
More information about the pypy-issue
mailing list