Description
Bug report
Bug description:
next()
on a shared itertools.cycle()
iterator may raise a StopIteration. With the GIL, that would never happen because the iterator loops forever. I think that's fine -- the iterator doesn't need to be thread-safe -- but the test needs to be fixed.
test_cycle (test.test_free_threading.test_itertools.ItertoolsThreading.test_cycle) ... Warning -- Uncaught thread exception: StopIteration
Exception in thread Thread-7130 (work):
Traceback (most recent call last):
File "/.../checkout/Lib/threading.py", line 1074, in _bootstrap_inner
self._context.run(self.run)
~~~~~~~~~~~~~~~~~^^^^^^^^^^
File "/.../checkout/Lib/threading.py", line 1016, in run
self._target(*self._args, **self._kwargs)
~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/.../checkout/Lib/test/test_free_threading/test_itertools.py", line 47, in work
_ = next(it)
StopIteration
ok
The problem is that the underlying iterator may be exhausted:
cpython/Modules/itertoolsmodule.c
Line 1203 in cb39410
But the other thread's may not have added anything to lz->saved
yet:
cpython/Modules/itertoolsmodule.c
Line 1205 in cb39410
Exit code path (leads to StopIteration):
cpython/Modules/itertoolsmodule.c
Lines 1220 to 1221 in cb39410
cc @eendebakpt @kumaraditya303
CPython versions tested on:
CPython main branch
Operating systems tested on:
No response