Message363402
| Author |
gregory.p.smith |
| Recipients |
Erik.Tollerud, amaury.forgeotdarc, eric.araujo, eric.snow, gregory.p.smith, meador.inge, psimons, python-dev, serhiy.storchaka, tomdzk |
| Date |
2020年03月04日.22:57:53 |
| SpamBayes Score |
-1.0 |
| Marked as misclassified |
Yes |
| Message-id |
<1583362673.32.0.468896555576.issue13487@roundup.psfhosted.org> |
| In-reply-to |
| Content |
fyi - we just had a test run into this (in a flaky manner - definitely a race condition) at work:
```
...
for f in inspect.stack(context=0)
File "<embedded stdlib>/inspect.py", line 1499, in stack
return getouterframes(sys._getframe(1), context)
File "<embedded stdlib>/inspect.py", line 1476, in getouterframes
frameinfo = (frame,) + getframeinfo(frame, context)
File "<embedded stdlib>/inspect.py", line 1446, in getframeinfo
filename = getsourcefile(frame) or getfile(frame)
File "<embedded stdlib>/inspect.py", line 696, in getsourcefile
if getattr(getmodule(object, filename), '__loader__', None) is not None:
File "<embedded stdlib>/inspect.py", line 732, in getmodule
for modname, module in list(sys.modules.items()):
RuntimeError: dictionary changed size during iteration
```
We haven't diagnosed what was leading to it though. Trust in the ability to use inspect.stack() -> ... -> inspect.getmodule() in multithreaded code is on the way out as a workaround.
(this was on 3.6.7)
A workaround we could checkin without consequences should be to change
list(sys.modules.items()) into list(sys.modules.copy().items()).
I was a bit surprised to see this happen at all, list(dict.items()) seems like it should've been done entirely in C with the GIL held the entire time. but maybe I'm just missing where the GIL would be released in the calls to exhause the iterator made by https://github.com/python/cpython/blob/master/Objects/listobject.c ? |
|