diff --git a/CHANGES.rst b/CHANGES.rst index 34bb8e139..81e4fbb19 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -23,8 +23,10 @@ upgrading your version of coverage.py. Unreleased ---------- -Nothing yet. +- Fix: in some cases, coverage could fail with a RuntimeError: "Set changed + size during iteration." This is now fixed, closing `issue 1733`_. +.. _issue 1733: https://github.com/nedbat/coveragepy/issues/1733 .. scriv-start-here diff --git a/coverage/collector.py b/coverage/collector.py index 87cd620e3..dcb8a30dd 100644 --- a/coverage/collector.py +++ b/coverage/collector.py @@ -513,9 +513,12 @@ def flush_data(self) -> bool: # these packed ints. arc_data: Dict[str, List[TArc]] = {} packed_data = cast(Dict[str, Set[int]], self.data) - for fname, packeds in packed_data.items(): + + # The list() here and in the inner loop are to get a clean copy + # even as tracers are continuing to add data. + for fname, packeds in list(packed_data.items()): tuples = [] - for packed in packeds: + for packed in list(packeds): l1 = packed & 0xFFFFF l2 = (packed & (0xFFFFF << 20)) >> 20 if packed & (1 << 40):