-
Notifications
You must be signed in to change notification settings - Fork 5.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Clean up sys.modules when the loader is GC'ed
This is done in two stages, first, the module instance in `sys.modules` is set to `None`. Then at a second stage, when creating a loader with the same namespace, it's actually removed from `sys.modules`. The reason for this two stage cleanup procedure is because this function might get called during the GC collection cycle and trigger https://bugs.python.org/issue40327 We seem to specially trigger this during the CI test runs with `coverage.py` tracking the code usage: Traceback (most recent call last): File "/urs/lib64/python3.6/site-packages/coverage/multiproc.py", line 37, in _bootstrap cov.start() File "/urs/lib64/python3.6/site-packages/coverage/control.py", line 527, in start self._init_for_start() File "/urs/lib64/python3.6/site-packages/coverage/control.py", line 455, in _init_for_start concurrency=concurrency, File "/urs/lib64/python3.6/site-packages/coverage/collector.py", line 111, in __init__ self.origin = short_stack() File "/urs/lib64/python3.6/site-packages/coverage/debug.py", line 157, in short_stack stack = inspect.stack()[limit:skip:-1] File "/usr/lib64/python3.6/inspect.py", line 1501, in stack return getouterframes(sys._getframe(1), context) File "/usr/lib64/python3.6/inspect.py", line 1478, in getouterframes frameinfo = (frame,) + getframeinfo(frame, context) File "/usr/lib64/python3.6/inspect.py", line 1452, in getframeinfo lines, lnum = findsource(frame) File "/usr/lib64/python3.6/inspect.py", line 780, in findsource module = getmodule(object, file) File "/usr/lib64/python3.6/inspect.py", line 732, in getmodule for modname, module in list(sys.modules.items()): RuntimeError: dictionary changed size during iteration
- Loading branch information
Showing
2 changed files
with
153 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters