pypy/module/_io/test/apptest_textio.py::test_concurrent_next_at_eof
tempfile = W_UnicodeObject('/private/tmp/buildbot-arm64/pytest/pytest-of-matti/pytest-1122/tempfile')
def test_concurrent_next_at_eof(tempfile):
# https://github.com/pypy/pypy/issues/5575
# Two threads iterating the same TextIOWrapper over a real fd can race
# inside the decode buffer when the underlying read() releases the GIL,
# especially right at EOF where DecodeBuffer.reset() nulls out its state.
import _thread
import time
with _io.open(tempfile, 'wb') as w:
w.write(b"line\n")
f = _io.TextIOWrapper(_io.BufferedReader(_io.FileIO(tempfile, "r")))
it = iter(f)
done = []
def worker():
for _ in range(10):
try:
next(it)
except Exception:
pass
done.append(1)
_thread.start_new_thread(worker, ())
_thread.start_new_thread(worker, ())
deadline = time.time() + 15.0
while len(done) < 2:
> assert time.time() < deadline, "worker threads hung (see issue 5575)"
E (application-level) AssertionError: worker threads hung (see issue 5575)
E assert 1788838114.336256 < 1788838113.521436
E + where 1788838114.336256 = <built-in function time>()
E + where <built-in function time> = <module 'time' (built-in)>.time
module/_io/test/apptest_textio.py:852: AssertionError
builder: own-macos-arm64 build #1379+
test: pypy/module/_io/test/apptest_textio.py::test_concurrent_next_at_eof