Skip to content

Commit 08fc997

Browse files
committed
fix: get atomic copies of iterables when flushing data. #1733
1 parent 4e34571 commit 08fc997

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

CHANGES.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,10 @@ upgrading your version of coverage.py.
2323
Unreleased
2424
----------
2525

26-
Nothing yet.
26+
- Fix: in some cases, coverage could fail with a RuntimeError: "Set changed
27+
size during iteration." This is now fixed, closing `issue 1733`_.
2728

29+
.. _issue 1733: https://github.com/nedbat/coveragepy/issues/1733
2830

2931
.. scriv-start-here
3032

coverage/collector.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -513,9 +513,12 @@ def flush_data(self) -> bool:
513513
# these packed ints.
514514
arc_data: Dict[str, List[TArc]] = {}
515515
packed_data = cast(Dict[str, Set[int]], self.data)
516-
for fname, packeds in packed_data.items():
516+
517+
# The list() here and in the inner loop are to get a clean copy
518+
# even as tracers are continuing to add data.
519+
for fname, packeds in list(packed_data.items()):
517520
tuples = []
518-
for packed in packeds:
521+
for packed in list(packeds):
519522
l1 = packed & 0xFFFFF
520523
l2 = (packed & (0xFFFFF << 20)) >> 20
521524
if packed & (1 << 40):

0 commit comments

Comments
 (0)