Skip to content

Commit

Permalink
fix: get atomic copies of iterables when flushing data. nedbat#1733
Browse files Browse the repository at this point in the history
  • Loading branch information
nedbat authored and hugovk committed Feb 24, 2024
1 parent 4c5581f commit f2b4719
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
4 changes: 3 additions & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 5 additions & 2 deletions coverage/collector.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit f2b4719

Please sign in to comment.