Skip to content

Commit

Permalink
fix: avoid a dict-changed-size error
Browse files Browse the repository at this point in the history
Windows 3.12 failed occasionally with this error:

```
      @panopticon()
      def stop(self) -> None:
          """Stop this Tracer."""
          if not self.sysmon_on:
              # In forking situations, we might try to stop when we are not
              # started.  Do nothing in that case.
              return
          assert sys_monitoring is not None
          sys_monitoring.set_events(self.myid, 0)
  >       for code in self.local_event_codes.values():
  E       RuntimeError: dictionary changed size during iteration
```

By setting self.sysmon_on=False before iteration, we lessen the chance
of adding an item to the dict during the iteration.
  • Loading branch information
nedbat committed Feb 14, 2024
1 parent 8412054 commit 628c1c5
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion coverage/sysmon.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,11 +251,11 @@ def stop(self) -> None:
return
assert sys_monitoring is not None
sys_monitoring.set_events(self.myid, 0)
self.sysmon_on = False
for code in self.local_event_codes.values():
sys_monitoring.set_local_events(self.myid, code, 0)
self.local_event_codes = {}
sys_monitoring.free_tool_id(self.myid)
self.sysmon_on = False

@panopticon()
def post_fork(self) -> None:
Expand Down

0 comments on commit 628c1c5

Please sign in to comment.